Skip to contentSkip to conversation

Enable 'ums' command on Trats2 board.

PATCH Superseded Piotr Wilczek 3 participants 8 messages Apr 10, 2013 – Jun 26, 2013 USB

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Enable 'ums' command on Trats2 board.

This patchset enable 'ums' command on Trats2 board. Definitions are added to pmic max77693 to enable safeout outputs. USB s3c_udc is modified to support Exnos4x12

Piotr Wilczek (4):
driver:usb:s3c_udc: add support for Exynos4x12 usb:composite: use memcpy to avoid unaligned access
pmic: max77693: add defines for safeout 1 and 2
trats2: enable ums support on Trats2

 board/samsung/trats2/trats2.c    |  133 ++++++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/composite.c   |    3 +-
 drivers/usb/gadget/regs-otg.h    |    5 ++
 drivers/usb/gadget/s3c_udc_otg.c |    9 ++-
 include/configs/trats2.h         |   19 ++++++
 include/power/max77693_pmic.h    |    3 +
 6 files changed, 169 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/4 driver:usb:s3c_udc: add support for Exynos4x12

This patch add new defines for usb phy for Exynos4x12.

---
 drivers/usb/gadget/regs-otg.h    |    5 +++++
 drivers/usb/gadget/s3c_udc_otg.c |    9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
drivers/usb/gadget/regs-otg.h +5 -0
index 3737e45..df7cda6 100644
@@ -229,6 +229,11 @@ struct s3c_usbotg_reg {
 #define CLK_SEL_12MHZ                   (0x2 << 0)
 #define CLK_SEL_48MHZ                   (0x0 << 0)
 
+#define EXYNOS4X12_ID_PULLUP0		(0x01 << 3)
+#define EXYNOS4X12_COMMON_ON_N0		(0x01 << 4)
+#define EXYNOS4X12_CLK_SEL_12MHZ	(0x02 << 0)
+#define EXYNOS4X12_CLK_SEL_24MHZ	(0x05 << 0)
+
 /* Device Configuration Register DCFG */
 #define DEV_SPEED_HIGH_SPEED_20         (0x0 << 0)
 #define DEV_SPEED_FULL_SPEED_20         (0x1 << 0)
drivers/usb/gadget/s3c_udc_otg.c +7 -2
index f9d24e3..fb72662 100644
@@ -180,8 +180,13 @@ void otg_phy_init(struct s3c_udc *dev)
 		writel((readl(&phy->phypwr) &~(OTG_DISABLE_0 | ANALOG_PWRDOWN)
 			&~FORCE_SUSPEND_0), &phy->phypwr);
 
-	writel((readl(&phy->phyclk) &~(ID_PULLUP0 | COMMON_ON_N0)) |
-	       CLK_SEL_24MHZ, &phy->phyclk); /* PLL 24Mhz */
+	if (proid_is_exynos4412())
+		writel((readl(&phy->phyclk) &~(EXYNOS4X12_ID_PULLUP0 |
+			EXYNOS4X12_COMMON_ON_N0)) | EXYNOS4X12_CLK_SEL_24MHZ,
+		       &phy->phyclk); /* PLL 24Mhz */
+	else
+		writel((readl(&phy->phyclk) &~(ID_PULLUP0 | COMMON_ON_N0)) |
+		       CLK_SEL_24MHZ, &phy->phyclk); /* PLL 24Mhz */
 
 	writel((readl(&phy->rstcon) &~(LINK_SW_RST | PHYLNK_SW_RST))
 	       | PHY_SW_RST0, &phy->rstcon);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/4 usb:composite: use memcpy to avoid unaligned access

In reply to Piotr Wilczek

This patch memcpy is used instead of an assignment to avoid unaligned access execption on some ARM platforms.

---
 drivers/usb/gadget/composite.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/composite.c +2 -1
index 2c5600e..0716e52 100644
@@ -997,7 +997,8 @@ static int composite_bind(struct usb_gadget *gadget)
 	if (status < 0)
 		goto fail;
 
-	cdev->desc = *composite->dev;
+	memcpy(&cdev->desc, composite->dev,
+	       sizeof(struct usb_device_descriptor));
 	cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 
 	debug("%s: ready\n", composite->name);
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 2/4 usb:composite: use memcpy to avoid unaligned access

Hello Piotr,

Am 10.04.2013 14:07, schrieb Piotr Wilczek:

Quoted 9 lines

This patch memcpy is used instead of an assignment to avoid unaligned access execption on some ARM platforms.

---
 drivers/usb/gadget/composite.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

just digged into this bug on an am335x based board, this patch helped me out!

Thanks!

bye,
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#4 lore raw

PATCH 2/4 usb:composite: use memcpy to avoid unaligned access

In reply to Piotr Wilczek

Hello Prafulla,

just saw, that the below patch is delegated to you:
(added also Marek Vasut to cc, as he is the usb maintainer)

Am 10.04.2013 14:07, schrieb Piotr Wilczek:

Quoted 16 lines

This patch memcpy is used instead of an assignment to avoid unaligned access execption on some ARM platforms.

---
 drivers/usb/gadget/composite.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/composite.c +0 -0
index 2c5600e..0716e52 100644

drivers/usb/gadget/composite.c static int composite_bind(struct usb_gadget *gadget) · line 1004

Quoted 9 lines
drivers/usb/gadget/composite.c +2 -1
@@ -997,7 +997,8 @@ static int composite_bind(struct usb_gadget *gadget)
 	if (status < 0)
 		goto fail;
 
-	cdev->desc = *composite->dev;
+	memcpy(&cdev->desc, composite->dev,
+	       sizeof(struct usb_device_descriptor));
 	cdev->desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
 
 	debug("%s: ready\n", composite->name);

This fixes a bug... do you plan to work it in for this release? Or are there some issues with this patch?

bye,
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Applied
#5 lore raw

PATCH 2/4 usb:composite: use memcpy to avoid unaligned access

Dear Heiko Schocher,

Quoted 4 lines

Hello Prafulla,

just saw, that the below patch is delegated to you:
(added also Marek Vasut to cc, as he is the usb maintainer)

Applied

Best regards,
Marek Vasut

#6 lore raw

PATCH 3/4 pmic: max77693: add defines for safeout 1 and 2

In reply to Piotr Wilczek
---
 include/power/max77693_pmic.h |    3 +++
 1 file changed, 3 insertions(+)
include/power/max77693_pmic.h +3 -0
index 07c3dd6..c43ace0 100644
@@ -50,6 +50,9 @@ enum {CHARGER_ENABLE, CHARGER_DISABLE};
 #define MAX77693_CHG_LOCK	(0x0 << 2)	/* MAX77693_CHG_CNFG_06	*/
 #define MAX77693_CHG_UNLOCK	(0x3 << 2)	/* MAX77693_CHG_CNFG_06	*/
 
+#define MAX77693_ENSAFEOUT1     (1 << 6)
+#define MAX77693_ENSAFEOUT2     (1 << 7)
+
 #define MAX77693_PMIC_I2C_ADDR	(0xCC >> 1)
 
 int pmic_init_max77693(unsigned char bus);
Signature · 1 line
1.7.9.5
#7 lore raw

PATCH 4/4 trats2: enable ums support on Trats2

In reply to Piotr Wilczek

This patch enables 'ums' command on Trats2 board.

---
 board/samsung/trats2/trats2.c |  133 +++++++++++++++++++++++++++++++++++++++++
 include/configs/trats2.h      |   19 ++++++
 2 files changed, 152 insertions(+)
board/samsung/trats2/trats2.c +133 -0
index 32fb699..d9de862 100644
@@ -45,6 +45,8 @@
 #include <power/max77693_fg.h>
 #include <libtizen.h>
 #include <errno.h>
+#include <usb/s3c_udc.h>
+#include <usb_mass_storage.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -326,6 +328,75 @@ int board_mmc_init(bd_t *bis)
 	return err;
 }
 
+#ifdef CONFIG_USB_GADGET
+static int s5pc210_phy_control(int on)
+{
+	int ret = 0;
+	unsigned int val;
+
+	struct pmic *p = pmic_get("MAX77686_PMIC");
+	if (!p)
+		return -ENODEV;
+
+	if (pmic_probe(p))
+		return -1;
+
+	if (on) {
+		ret = max77686_set_ldo_mode(p, 12, OPMODE_ON);
+
+		p = pmic_get("MAX77693_PMIC");
+		pmic_probe(p);
+		if (pmic_probe(p))
+			return -1;
+
+		/* SAFEOUT */
+		ret |= pmic_reg_read(p, MAX77693_SAFEOUT, &val);
+		val |= MAX77693_ENSAFEOUT1;
+		ret |= pmic_reg_write(p, MAX77693_SAFEOUT, val);
+
+		p = pmic_get("MAX77693_MUIC");
+		if (pmic_probe(p))
+			return -1;
+
+		/* PATH: USB */
+		ret |= pmic_reg_write(p, MAX77693_MUIC_CONTROL1,
+			MAX77693_MUIC_CTRL1_DN1DP2);
+
+	} else {
+		ret |= max77686_set_ldo_mode(p, 12, OPMODE_LPM);
+
+		p = pmic_get("MAX77693_MUIC");
+		if (pmic_probe(p))
+			return -1;
+
+		/* PATH: UART */
+		ret |= pmic_reg_write(p, MAX77693_MUIC_CONTROL1,
+			MAX77693_MUIC_CTRL1_UT1UR2);
+	}
+
+	if (ret) {
+		puts("MAX77693 setting error!\n");
+		return -1;
+	}
+
+	return 0;
+}
+
+struct s3c_plat_otg_data s5pc210_otg_data = {
+	.phy_control	= s5pc210_phy_control,
+	.regs_phy	= EXYNOS4X12_USBPHY_BASE,
+	.regs_otg	= EXYNOS4X12_USBOTG_BASE,
+	.usb_phy_ctrl	= EXYNOS4X12_USBPHY_CONTROL,
+	.usb_flags	= PHY0_SLEEP,
+};
+
+void board_usb_init(void)
+{
+	debug("USB_udc_probe\n");
+	s3c_udc_probe(&s5pc210_otg_data);
+}
+#endif
+
 static int pmic_init_max77686(void)
 {
 	struct pmic *p = pmic_get("MAX77686_PMIC");
@@ -525,3 +596,65 @@ int misc_init_r(void)
 	return 0;
 }
 #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 = "TRATS2 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
include/configs/trats2.h +19 -0
index 5637734..8f86d8c 100644
@@ -133,6 +133,16 @@
 #define CONFIG_CMD_EXT4
 #define CONFIG_CMD_EXT4_WRITE
 
+/* USB Composite download gadget - g_dnl */
+#define CONFIG_USBDOWNLOAD_GADGET
+#define CONFIG_DFU_FUNCTION
+#define CONFIG_DFU_MMC
+
+/* USB Samsung's IDs */
+#define CONFIG_G_DNL_VENDOR_NUM 0x04E8
+#define CONFIG_G_DNL_PRODUCT_NUM 0x6601
+#define CONFIG_G_DNL_MANUFACTURER "Samsung"
+
 /* To use the TFTPBOOT over USB, Please enable the CONFIG_CMD_NET */
 #undef CONFIG_CMD_NET
 
@@ -288,6 +298,10 @@
 #define CONFIG_POWER_MUIC_MAX77693
 #define CONFIG_POWER_FG_MAX77693
 #define CONFIG_POWER_BATTERY_TRATS2
+#define CONFIG_USB_GADGET
+#define CONFIG_USB_GADGET_S3C_UDC_OTG
+#define CONFIG_USB_GADGET_DUALSPEED
+#define CONFIG_USB_GADGET_VBUS_DRAW	2
 
 /* PWM */
 #define CONFIG_PWM
@@ -306,4 +320,9 @@
 #define CONFIG_VIDEO_BMP_GZIP
 #define CONFIG_SYS_VIDEO_LOGO_MAX_SIZE ((500 * 250 * 4) + (1 << 12))
 
+#define CONFIG_CMD_USB_MASS_STORAGE
+#if defined(CONFIG_CMD_USB_MASS_STORAGE)
+#define CONFIG_USB_GADGET_MASS_STORAGE
+#endif
+
 #endif	/* __CONFIG_H */
Signature · 1 line
1.7.9.5