Patchwork [U-Boot,3/3] arm:goni: Add support for USB mass storage

login
register
mail settings
Submitter a.wlodarczyk@samsung.com
Date Feb. 18, 2013, 10:18 a.m.
Message ID <1361182686-16882-3-git-send-email-a.wlodarczyk@samsung.com>
Download mbox | patch
Permalink /patch/221245/
State Changes Requested
Delegated to: Minkyu Kang
Headers show

Comments

a.wlodarczyk@samsung.com - Feb. 18, 2013, 10:18 a.m.
From: Arkadiusz Wlodarczyk <a.wlodarczyk@samsung.com>

Signed-off-by: Arkadiusz Wlodarczyk <a.wlodarczyk@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Tested-by: Arkadiusz Wlodarczyk <a.wlodarczyk@samsung.com>
Cc: Minkyu Kang <mk7.kang@samsung.com>
---
Changes
Switch on USB gadget mass storage and ums command in
configuration for goni target; Add code supporting USB gadget
mass storage in board/samsung/goni/goni.c
---
Depends on implementation of USB mass storage
for Samsung.
http://patchwork.ozlabs.org/patch/219744/
http://patchwork.ozlabs.org/patch/219746/
http://patchwork.ozlabs.org/patch/219745/
---
 board/samsung/goni/goni.c  |   68 ++++++++++++++++++++++++++++++++++++++++++++
 include/configs/s5p_goni.h |    5 +++
 2 files changed, 73 insertions(+), 0 deletions(-)
Minkyu Kang - March 27, 2013, 2:46 a.m.
Dear Arkadiusz Wlodarczyk,

On 18/02/13 19:18, a.wlodarczyk@samsung.com wrote:
> From: Arkadiusz Wlodarczyk <a.wlodarczyk@samsung.com>
> 
> Signed-off-by: Arkadiusz Wlodarczyk <a.wlodarczyk@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> Tested-by: Arkadiusz Wlodarczyk <a.wlodarczyk@samsung.com>
> Cc: Minkyu Kang <mk7.kang@samsung.com>
> ---
> Changes
> Switch on USB gadget mass storage and ums command in
> configuration for goni target; Add code supporting USB gadget
> mass storage in board/samsung/goni/goni.c
> ---
> Depends on implementation of USB mass storage
> for Samsung.
> http://patchwork.ozlabs.org/patch/219744/
> http://patchwork.ozlabs.org/patch/219746/
> http://patchwork.ozlabs.org/patch/219745/
> ---
>  board/samsung/goni/goni.c  |   68 ++++++++++++++++++++++++++++++++++++++++++++
>  include/configs/s5p_goni.h |    5 +++
>  2 files changed, 73 insertions(+), 0 deletions(-)
> 
> diff --git a/board/samsung/goni/goni.c b/board/samsung/goni/goni.c
> index 3c53106..a09daca 100644
> --- a/board/samsung/goni/goni.c
> +++ b/board/samsung/goni/goni.c
> @@ -29,6 +29,7 @@
>  #include <usb/s3c_udc.h>
>  #include <asm/arch/cpu.h>
>  #include <power/max8998_pmic.h>
> +#include <usb_mass_storage.h>
>  DECLARE_GLOBAL_DATA_PTR;
>  
>  static struct s5pc110_gpio *s5pc110_gpio;
> @@ -163,3 +164,70 @@ void board_usb_init(void)
>  }
>  
>  #endif
> +
> +#ifdef CONFIG_USB_GADGET_MASS_STORAGE
> +static int ums_read_sector(struct ums_device *ums_dev,
> +				ulong start, lbaint_t blkcnt, void *buf)
> +{
> +	if (ums_dev->mmc->block_dev.block_read(ums_dev->dev_num,
> +			start + ums_dev->offset, blkcnt, buf) != blkcnt)
> +		return -1;
> +
> +	return 0;
> +}
> +
> +static int ums_write_sector(struct ums_device *ums_dev,
> +				ulong start, lbaint_t blkcnt, const void *buf)
> +{
> +	if (ums_dev->mmc->block_dev.block_write(ums_dev->dev_num,
> +			start + ums_dev->offset, blkcnt, buf) != blkcnt)
> +			return -1;
> +
> +	return 0;
> +}
> +
> +static void ums_get_capacity(struct ums_device *ums_dev,
> +					long long int *capacity)
> +{
> +	long long int tmp_capacity;
> +
> +	tmp_capacity = (long long int) ((ums_dev->offset + ums_dev->part_size)
> +					* SECTOR_SIZE);
> +	*capacity = ums_dev->mmc->capacity - tmp_capacity;
> +}
> +
> +static struct ums_board_info ums_board = {
> +	.read_sector = ums_read_sector,
> +	.write_sector = ums_write_sector,
> +	.get_capacity = ums_get_capacity,
> +	.name = "GONI UMS disk",
> +	.ums_dev = {
> +		.mmc = NULL,
> +		.dev_num = 0,
> +		.offset = 0,
> +		.part_size = 0.
> +	},
> +};
> +
> +struct ums_board_info *board_ums_init(unsigned int dev_num, unsigned int offset,
> +					unsigned int part_size)
> +{
> +	struct mmc *mmc;
> +
> +	mmc = find_mmc_device(dev_num);
> +	/* mmc initialization is necessary prior to the ums command usage
> +	 * due to fact that on goni target environment is read from oneNand
> +	 * memory, so the mmc remains uninitialized whenu-boot prompt appears
> +	 * */

please check multi line comments rule.

> +	if (!mmc || mmc_init(mmc))

why don't you separate this statement?

> +		return NULL;
> +
> +	ums_board.ums_dev.mmc = mmc;
> +	ums_board.ums_dev.dev_num = dev_num;
> +	ums_board.ums_dev.offset = offset;
> +	ums_board.ums_dev.part_size = part_size;
> +
> +	return &ums_board;
> +}
> +
> +#endif
> diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
> index e8f2639..1cfbb88 100644
> --- a/include/configs/s5p_goni.h
> +++ b/include/configs/s5p_goni.h
> @@ -269,4 +269,9 @@
>  #define CONFIG_USB_GADGET_DUALSPEED
>  #define CONFIG_USB_GADGET_VBUS_DRAW 2
>  
> +#define CONFIG_CMD_USB_MASS_STORAGE
> +#if defined(CONFIG_CMD_USB_MASS_STORAGE)

I think, this ifdef is unnecessary.

> +#define CONFIG_USB_GADGET_MASS_STORAGE
> +#endif
> +
>  #endif	/* __CONFIG_H */
> 

Thanks,
Minkyu Kang.

Patch

diff --git a/board/samsung/goni/goni.c b/board/samsung/goni/goni.c
index 3c53106..a09daca 100644
--- a/board/samsung/goni/goni.c
+++ b/board/samsung/goni/goni.c
@@ -29,6 +29,7 @@ 
 #include <usb/s3c_udc.h>
 #include <asm/arch/cpu.h>
 #include <power/max8998_pmic.h>
+#include <usb_mass_storage.h>
 DECLARE_GLOBAL_DATA_PTR;
 
 static struct s5pc110_gpio *s5pc110_gpio;
@@ -163,3 +164,70 @@  void board_usb_init(void)
 }
 
 #endif
+
+#ifdef CONFIG_USB_GADGET_MASS_STORAGE
+static int ums_read_sector(struct ums_device *ums_dev,
+				ulong start, lbaint_t blkcnt, void *buf)
+{
+	if (ums_dev->mmc->block_dev.block_read(ums_dev->dev_num,
+			start + ums_dev->offset, blkcnt, buf) != blkcnt)
+		return -1;
+
+	return 0;
+}
+
+static int ums_write_sector(struct ums_device *ums_dev,
+				ulong start, lbaint_t blkcnt, const void *buf)
+{
+	if (ums_dev->mmc->block_dev.block_write(ums_dev->dev_num,
+			start + ums_dev->offset, blkcnt, buf) != blkcnt)
+			return -1;
+
+	return 0;
+}
+
+static void ums_get_capacity(struct ums_device *ums_dev,
+					long long int *capacity)
+{
+	long long int tmp_capacity;
+
+	tmp_capacity = (long long int) ((ums_dev->offset + ums_dev->part_size)
+					* SECTOR_SIZE);
+	*capacity = ums_dev->mmc->capacity - tmp_capacity;
+}
+
+static struct ums_board_info ums_board = {
+	.read_sector = ums_read_sector,
+	.write_sector = ums_write_sector,
+	.get_capacity = ums_get_capacity,
+	.name = "GONI UMS disk",
+	.ums_dev = {
+		.mmc = NULL,
+		.dev_num = 0,
+		.offset = 0,
+		.part_size = 0.
+	},
+};
+
+struct ums_board_info *board_ums_init(unsigned int dev_num, unsigned int offset,
+					unsigned int part_size)
+{
+	struct mmc *mmc;
+
+	mmc = find_mmc_device(dev_num);
+	/* mmc initialization is necessary prior to the ums command usage
+	 * due to fact that on goni target environment is read from oneNand
+	 * memory, so the mmc remains uninitialized whenu-boot prompt appears
+	 * */
+	if (!mmc || mmc_init(mmc))
+		return NULL;
+
+	ums_board.ums_dev.mmc = mmc;
+	ums_board.ums_dev.dev_num = dev_num;
+	ums_board.ums_dev.offset = offset;
+	ums_board.ums_dev.part_size = part_size;
+
+	return &ums_board;
+}
+
+#endif
diff --git a/include/configs/s5p_goni.h b/include/configs/s5p_goni.h
index e8f2639..1cfbb88 100644
--- a/include/configs/s5p_goni.h
+++ b/include/configs/s5p_goni.h
@@ -269,4 +269,9 @@ 
 #define CONFIG_USB_GADGET_DUALSPEED
 #define CONFIG_USB_GADGET_VBUS_DRAW 2
 
+#define CONFIG_CMD_USB_MASS_STORAGE
+#if defined(CONFIG_CMD_USB_MASS_STORAGE)
+#define CONFIG_USB_GADGET_MASS_STORAGE
+#endif
+
 #endif	/* __CONFIG_H */