Patchwork [U-Boot,1/4] usb: ums: move ums code from trats to Samsung common directory

login
register
mail settings
Submitter Przemyslaw Marczak
Date Oct. 16, 2013, 1:21 p.m.
Message ID <1381929675-26165-2-git-send-email-p.marczak@samsung.com>
Download mbox | patch
Permalink /patch/283942/
State Superseded
Delegated to: Marek Vasut
Headers show

Comments

Przemyslaw Marczak - Oct. 16, 2013, 1:21 p.m.
UMS init was implemented in trats board file but mostly it comprises
common code. Due to that it has been moved to common/ums.c to avoid
code duplication in the future.

Changes:
- move ums initialization code from trats to common/ums.c
- remove unused CONFIG_USB_GADGET_MASS_STORAGE from trats.h

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
Cc: Marek Vasut <marex@denx.de>
Cc: Minkyu Kang <mk7.kang@samsung.com>
Cc: Lukasz Majewski <l.majewski@samsung.com>
---
 board/samsung/common/Makefile |    1 +
 board/samsung/common/ums.c    |   66 +++++++++++++++++++++++++++++++++++++++++
 board/samsung/trats/trats.c   |   62 --------------------------------------
 include/configs/trats.h       |    2 --
 4 files changed, 67 insertions(+), 64 deletions(-)
 create mode 100644 board/samsung/common/ums.c
Marek Vasut - Oct. 17, 2013, 5:39 p.m.
Dear Przemyslaw Marczak,

> UMS init was implemented in trats board file but mostly it comprises
> common code. Due to that it has been moved to common/ums.c to avoid
> code duplication in the future.
> 
> Changes:
> - move ums initialization code from trats to common/ums.c
> - remove unused CONFIG_USB_GADGET_MASS_STORAGE from trats.h
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> Cc: Marek Vasut <marex@denx.de>
> Cc: Minkyu Kang <mk7.kang@samsung.com>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> ---
>  board/samsung/common/Makefile |    1 +
>  board/samsung/common/ums.c    |   66
> +++++++++++++++++++++++++++++++++++++++++ board/samsung/trats/trats.c   | 
>  62 -------------------------------------- include/configs/trats.h       |
>    2 --
>  4 files changed, 67 insertions(+), 64 deletions(-)
>  create mode 100644 board/samsung/common/ums.c
> 
> diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile
> index ad7564c..d122169 100644
> --- a/board/samsung/common/Makefile
> +++ b/board/samsung/common/Makefile
> @@ -11,6 +11,7 @@ LIB	= $(obj)libsamsung.o
> 
>  COBJS-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o
>  COBJS-$(CONFIG_THOR_FUNCTION) += thor.o
> +COBJS-$(CONFIG_CMD_USB_MASS_STORAGE) += ums.o
> 
>  SRCS    := $(COBJS-y:.o=.c)
>  OBJS	:= $(addprefix $(obj),$(COBJS-y))
> diff --git a/board/samsung/common/ums.c b/board/samsung/common/ums.c
> new file mode 100644
> index 0000000..506f4b5
> --- /dev/null
> +++ b/board/samsung/common/ums.c
> @@ -0,0 +1,66 @@
> +/*
> + * Copyright (C) 2013 Samsung Electronics
> + * Lukasz Majewski <l.majewski@samsung.com>
> + *
> + * SPDX-License-Identifier:	GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <usb_mass_storage.h>
> +#include <part.h>
> +
> +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)

This looks like hell.

typeT block_dev = ums_dev->mmc;
int ret;

ret = block_dev->block_read(....);

return ret;

Is it necessary to return -1? Why ?

Please fix the whole thing in-place first, then rebase this migration patch on 
top of the fix.
Przemyslaw Marczak - Oct. 18, 2013, 11:38 a.m.
Hello Marek,
Thank you for fast reply.

On 10/17/2013 07:39 PM, Marek Vasut wrote:
> Dear Przemyslaw Marczak,
>
>> UMS init was implemented in trats board file but mostly it comprises
>> common code. Due to that it has been moved to common/ums.c to avoid
>> code duplication in the future.
>>
>> Changes:
>> - move ums initialization code from trats to common/ums.c
>> - remove unused CONFIG_USB_GADGET_MASS_STORAGE from trats.h
>>
>> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
>> Cc: Marek Vasut <marex@denx.de>
>> Cc: Minkyu Kang <mk7.kang@samsung.com>
>> Cc: Lukasz Majewski <l.majewski@samsung.com>
>> ---
>>   board/samsung/common/Makefile |    1 +
>>   board/samsung/common/ums.c    |   66
>> +++++++++++++++++++++++++++++++++++++++++ board/samsung/trats/trats.c   |
>>   62 -------------------------------------- include/configs/trats.h       |
>>     2 --
>>   4 files changed, 67 insertions(+), 64 deletions(-)
>>   create mode 100644 board/samsung/common/ums.c
>>
>> diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile
>> index ad7564c..d122169 100644
>> --- a/board/samsung/common/Makefile
>> +++ b/board/samsung/common/Makefile
>> @@ -11,6 +11,7 @@ LIB	= $(obj)libsamsung.o
>>
>>   COBJS-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o
>>   COBJS-$(CONFIG_THOR_FUNCTION) += thor.o
>> +COBJS-$(CONFIG_CMD_USB_MASS_STORAGE) += ums.o
>>
>>   SRCS    := $(COBJS-y:.o=.c)
>>   OBJS	:= $(addprefix $(obj),$(COBJS-y))
>> diff --git a/board/samsung/common/ums.c b/board/samsung/common/ums.c
>> new file mode 100644
>> index 0000000..506f4b5
>> --- /dev/null
>> +++ b/board/samsung/common/ums.c
>> @@ -0,0 +1,66 @@
>> +/*
>> + * Copyright (C) 2013 Samsung Electronics
>> + * Lukasz Majewski <l.majewski@samsung.com>
>> + *
>> + * SPDX-License-Identifier:	GPL-2.0+
>> + */
>> +
>> +#include <common.h>
>> +#include <usb_mass_storage.h>
>> +#include <part.h>
>> +
>> +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)
>
> This looks like hell.
>
> typeT block_dev = ums_dev->mmc;
> int ret;
>
> ret = block_dev->block_read(....);
>
> return ret;

Ok, you're right - I will fix it in next patch set.

>
> Is it necessary to return -1? Why ?
>

It's only because of ums gadged driver design but it is easy to simplify.

> Please fix the whole thing in-place first, then rebase this migration patch on
> top of the fix.
>

OK, migration patch will be at the top.

And one more. Do you want me to make it applicable to usb-next or 
usb-master tree?

Thank you for comments.
Marek Vasut - Oct. 18, 2013, 1:58 p.m.
Dear Przemyslaw Marczak,

> Hello Marek,
> Thank you for fast reply.
> 
> On 10/17/2013 07:39 PM, Marek Vasut wrote:
> > Dear Przemyslaw Marczak,
> > 
> >> UMS init was implemented in trats board file but mostly it comprises
> >> common code. Due to that it has been moved to common/ums.c to avoid
> >> code duplication in the future.
> >> 
> >> Changes:
> >> - move ums initialization code from trats to common/ums.c
> >> - remove unused CONFIG_USB_GADGET_MASS_STORAGE from trats.h
> >> 
> >> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> >> Cc: Marek Vasut <marex@denx.de>
> >> Cc: Minkyu Kang <mk7.kang@samsung.com>
> >> Cc: Lukasz Majewski <l.majewski@samsung.com>
> >> ---
> >> 
> >>   board/samsung/common/Makefile |    1 +
> >>   board/samsung/common/ums.c    |   66
> >> 
> >> +++++++++++++++++++++++++++++++++++++++++ board/samsung/trats/trats.c  
> >> |
> >> 
> >>   62 -------------------------------------- include/configs/trats.h     
> >>    |
> >>   
> >>     2 --
> >>   
> >>   4 files changed, 67 insertions(+), 64 deletions(-)
> >>   create mode 100644 board/samsung/common/ums.c
> >> 
> >> diff --git a/board/samsung/common/Makefile
> >> b/board/samsung/common/Makefile index ad7564c..d122169 100644
> >> --- a/board/samsung/common/Makefile
> >> +++ b/board/samsung/common/Makefile
> >> @@ -11,6 +11,7 @@ LIB	= $(obj)libsamsung.o
> >> 
> >>   COBJS-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o
> >>   COBJS-$(CONFIG_THOR_FUNCTION) += thor.o
> >> 
> >> +COBJS-$(CONFIG_CMD_USB_MASS_STORAGE) += ums.o
> >> 
> >>   SRCS    := $(COBJS-y:.o=.c)
> >>   OBJS	:= $(addprefix $(obj),$(COBJS-y))
> >> 
> >> diff --git a/board/samsung/common/ums.c b/board/samsung/common/ums.c
> >> new file mode 100644
> >> index 0000000..506f4b5
> >> --- /dev/null
> >> +++ b/board/samsung/common/ums.c
> >> @@ -0,0 +1,66 @@
> >> +/*
> >> + * Copyright (C) 2013 Samsung Electronics
> >> + * Lukasz Majewski <l.majewski@samsung.com>
> >> + *
> >> + * SPDX-License-Identifier:	GPL-2.0+
> >> + */
> >> +
> >> +#include <common.h>
> >> +#include <usb_mass_storage.h>
> >> +#include <part.h>
> >> +
> >> +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)
> > 
> > This looks like hell.
> > 
> > typeT block_dev = ums_dev->mmc;
> > int ret;
> > 
> > ret = block_dev->block_read(....);
> > 
> > return ret;
> 
> Ok, you're right - I will fix it in next patch set.
> 
> > Is it necessary to return -1? Why ?
> 
> It's only because of ums gadged driver design but it is easy to simplify.

A proper errno.h patch would be good here.

> > Please fix the whole thing in-place first, then rebase this migration
> > patch on top of the fix.
> 
> OK, migration patch will be at the top.
> 
> And one more. Do you want me to make it applicable to usb-next or
> usb-master tree?

-next please.

Patch

diff --git a/board/samsung/common/Makefile b/board/samsung/common/Makefile
index ad7564c..d122169 100644
--- a/board/samsung/common/Makefile
+++ b/board/samsung/common/Makefile
@@ -11,6 +11,7 @@  LIB	= $(obj)libsamsung.o
 
 COBJS-$(CONFIG_SOFT_I2C_MULTI_BUS) += multi_i2c.o
 COBJS-$(CONFIG_THOR_FUNCTION) += thor.o
+COBJS-$(CONFIG_CMD_USB_MASS_STORAGE) += ums.o
 
 SRCS    := $(COBJS-y:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS-y))
diff --git a/board/samsung/common/ums.c b/board/samsung/common/ums.c
new file mode 100644
index 0000000..506f4b5
--- /dev/null
+++ b/board/samsung/common/ums.c
@@ -0,0 +1,66 @@ 
+/*
+ * Copyright (C) 2013 Samsung Electronics
+ * Lukasz Majewski <l.majewski@samsung.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <usb_mass_storage.h>
+#include <part.h>
+
+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 = "UMS disk",
+};
+
+struct ums_board_info *board_ums_init(unsigned int dev_num, unsigned int offset,
+				      unsigned int part_size)
+{
+	struct mmc *mmc = NULL;
+
+	mmc = find_mmc_device(dev_num);
+	if (!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;
+}
diff --git a/board/samsung/trats/trats.c b/board/samsung/trats/trats.c
index 58d925f..db5828d 100644
--- a/board/samsung/trats/trats.c
+++ b/board/samsung/trats/trats.c
@@ -772,65 +772,3 @@  void init_panel_info(vidinfo_t *vid)
 
 	setenv("lcdinfo", "lcd=s6e8ax0");
 }
-
-#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 = "TRATS 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);
-	if (!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/trats.h b/include/configs/trats.h
index f5bb6aa..3e67229 100644
--- a/include/configs/trats.h
+++ b/include/configs/trats.h
@@ -323,9 +323,7 @@ 
 #define CONFIG_SYS_VIDEO_LOGO_MAX_SIZE ((500 * 120 * 4) + (1 << 12))
 
 #define CONFIG_CMD_USB_MASS_STORAGE
-#if defined(CONFIG_CMD_USB_MASS_STORAGE)
 #define CONFIG_USB_GADGET_MASS_STORAGE
-#endif
 
 /* Pass open firmware flat tree */
 #define CONFIG_OF_LIBFDT    1