* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-27 8:19 Felipe Balbi
0 siblings, 0 replies; 8+ messages in thread
From: Felipe Balbi @ 2018-07-27 8:19 UTC (permalink / raw)
To: Gevorg Sahakyan, Andy Shevchenko
Cc: Greg Kroah-Hartman, Minas Harutyunyan, USB, John Youn
Hi,
Gevorg Sahakyan <Gevorg.Sahakyan@synopsys.com> writes:
> @@ -1164,12 +1166,21 @@ struct dwc2_hsotg {
> /* Normal architectures just use readl/write */
> static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
> {
> - return readl(hsotg->regs + offset);
> + u32 val;
> +
> + val = readl(hsotg->regs + offset);
> + if (hsotg->needs_byte_swap)
> + return swab32(val);
> + else
> + return val;
> }
>
> static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32
> offset)
patch is mangled :(
^ permalink raw reply [flat|nested] 8+ messages in thread
* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-27 10:00 Felipe Balbi
0 siblings, 0 replies; 8+ messages in thread
From: Felipe Balbi @ 2018-07-27 10:00 UTC (permalink / raw)
To: Grigor Tovmasyan, Gevorg Sahakyan, Greg Kroah-Hartman,
Minas Harutyunyan, linux-usb
Cc: John Youn
hi,
Grigor Tovmasyan <Grigor.Tovmasyan@synopsys.com> writes:
>> @@ -395,6 +412,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
>> dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
>> (unsigned long)res->start, hsotg->regs);
>>
>> + hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg);
>> +
>> retval = dwc2_lowlevel_hw_init(hsotg);
>> if (retval)
>> return retval;
>>
>
> I believe this one will work :)
perfectly, I'll push it shortly
> Sorry for inconvenience.
not at all ;) Thanks
^ permalink raw reply [flat|nested] 8+ messages in thread
* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-27 8:41 Grigor Tovmasyan
0 siblings, 0 replies; 8+ messages in thread
From: Grigor Tovmasyan @ 2018-07-27 8:41 UTC (permalink / raw)
To: Gevorg Sahakyan, Felipe Balbi, Greg Kroah-Hartman,
Minas Harutyunyan, linux-usb
Cc: John Youn
Hi Felipe,
On 7/27/2018 12:26, Gevorg Sahakyan wrote:
> Declared dwc2_check_core_endianness() function for dynamicly check
> core endianness.
> Added needs_byte_swap flag to hsotg structure, and depending on
> flag swap value inside dwc2_readl/writel functions.
>
> Signed-off-by: Gevorg Sahakyan <sahakyan@synopsys.com>
> ---
> drivers/usb/dwc2/core.h | 15 +++++++++++++--
> drivers/usb/dwc2/platform.c | 19 +++++++++++++++++++
> 2 files changed, 32 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index ae8534b..cc9c93a 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -857,6 +857,7 @@ struct dwc2_hregs_backup {
> * @gr_backup: Backup of global registers during suspend
> * @dr_backup: Backup of device registers during suspend
> * @hr_backup: Backup of host registers during suspend
> + * @needs_byte_swap: Specifies whether the opposite endianness.
> *
> * These are for host mode:
> *
> @@ -1046,6 +1047,7 @@ struct dwc2_hsotg {
>
> struct dentry *debug_root;
> struct debugfs_regset32 *regset;
> + bool needs_byte_swap;
>
> /* DWC OTG HW Release versions */
> #define DWC2_CORE_REV_2_71a 0x4f54271a
> @@ -1164,12 +1166,21 @@ struct dwc2_hsotg {
> /* Normal architectures just use readl/write */
> static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
> {
> - return readl(hsotg->regs + offset);
> + u32 val;
> +
> + val = readl(hsotg->regs + offset);
> + if (hsotg->needs_byte_swap)
> + return swab32(val);
> + else
> + return val;
> }
>
> static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32 offset)
> {
> - writel(value, hsotg->regs + offset);
> + if (hsotg->needs_byte_swap)
> + writel(swab32(value), hsotg->regs + offset);
> + else
> + writel(value, hsotg->regs + offset);
>
> #ifdef DWC2_LOG_WRITES
> pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset);
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index 4c08195..9a53a58 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -353,6 +353,23 @@ static void dwc2_driver_shutdown(struct platform_device *dev)
> }
>
> /**
> + * dwc2_check_core_endianness() - Returns true if core and AHB have
> + * opposite endianness.
> + * @hsotg: Programming view of the DWC_otg controller.
> + */
> +static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg)
> +{
> + u32 snpsid;
> +
> + snpsid = ioread32(hsotg->regs + GSNPSID);
> + if ((snpsid & GSNPSID_ID_MASK) == DWC2_OTG_ID ||
> + (snpsid & GSNPSID_ID_MASK) == DWC2_FS_IOT_ID ||
> + (snpsid & GSNPSID_ID_MASK) == DWC2_HS_IOT_ID)
> + return false;
> + return true;
> +}
> +
> +/**
> * dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
> * driver
> *
> @@ -395,6 +412,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
> dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
> (unsigned long)res->start, hsotg->regs);
>
> + hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg);
> +
> retval = dwc2_lowlevel_hw_init(hsotg);
> if (retval)
> return retval;
>
I believe this one will work :)
Sorry for inconvenience.
Thanks,
Grigor
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-27 8:26 Gevorg Sahakyan
0 siblings, 0 replies; 8+ messages in thread
From: Gevorg Sahakyan @ 2018-07-27 8:26 UTC (permalink / raw)
To: Felipe Balbi, Greg Kroah-Hartman, Minas Harutyunyan, linux-usb
Cc: John Youn, Gevorg Sahakyan
Declared dwc2_check_core_endianness() function for dynamicly check
core endianness.
Added needs_byte_swap flag to hsotg structure, and depending on
flag swap value inside dwc2_readl/writel functions.
Signed-off-by: Gevorg Sahakyan <sahakyan@synopsys.com>
---
drivers/usb/dwc2/core.h | 15 +++++++++++++--
drivers/usb/dwc2/platform.c | 19 +++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index ae8534b..cc9c93a 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -857,6 +857,7 @@ struct dwc2_hregs_backup {
* @gr_backup: Backup of global registers during suspend
* @dr_backup: Backup of device registers during suspend
* @hr_backup: Backup of host registers during suspend
+ * @needs_byte_swap: Specifies whether the opposite endianness.
*
* These are for host mode:
*
@@ -1046,6 +1047,7 @@ struct dwc2_hsotg {
struct dentry *debug_root;
struct debugfs_regset32 *regset;
+ bool needs_byte_swap;
/* DWC OTG HW Release versions */
#define DWC2_CORE_REV_2_71a 0x4f54271a
@@ -1164,12 +1166,21 @@ struct dwc2_hsotg {
/* Normal architectures just use readl/write */
static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
{
- return readl(hsotg->regs + offset);
+ u32 val;
+
+ val = readl(hsotg->regs + offset);
+ if (hsotg->needs_byte_swap)
+ return swab32(val);
+ else
+ return val;
}
static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32 offset)
{
- writel(value, hsotg->regs + offset);
+ if (hsotg->needs_byte_swap)
+ writel(swab32(value), hsotg->regs + offset);
+ else
+ writel(value, hsotg->regs + offset);
#ifdef DWC2_LOG_WRITES
pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset);
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 4c08195..9a53a58 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -353,6 +353,23 @@ static void dwc2_driver_shutdown(struct platform_device *dev)
}
/**
+ * dwc2_check_core_endianness() - Returns true if core and AHB have
+ * opposite endianness.
+ * @hsotg: Programming view of the DWC_otg controller.
+ */
+static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg)
+{
+ u32 snpsid;
+
+ snpsid = ioread32(hsotg->regs + GSNPSID);
+ if ((snpsid & GSNPSID_ID_MASK) == DWC2_OTG_ID ||
+ (snpsid & GSNPSID_ID_MASK) == DWC2_FS_IOT_ID ||
+ (snpsid & GSNPSID_ID_MASK) == DWC2_HS_IOT_ID)
+ return false;
+ return true;
+}
+
+/**
* dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
* driver
*
@@ -395,6 +412,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
(unsigned long)res->start, hsotg->regs);
+ hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg);
+
retval = dwc2_lowlevel_hw_init(hsotg);
if (retval)
return retval;
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-27 8:19 Gevorg Sahakyan
0 siblings, 0 replies; 8+ messages in thread
From: Gevorg Sahakyan @ 2018-07-27 8:19 UTC (permalink / raw)
To: Felipe Balbi, Andy Shevchenko, Gevorg Sahakyan
Cc: Greg Kroah-Hartman, Minas Harutyunyan, USB, John Youn
Declared dwc2_check_core_endianness() function for dynamicly check
core endianness.
Added needs_byte_swap flag to hsotg structure, and depending on
flag swap value inside dwc2_readl/writel functions.
Signed-off-by: Gevorg Sahakyan <sahakyan@synopsys.com>
---
drivers/usb/dwc2/core.h | 15 +++++++++++++--
drivers/usb/dwc2/platform.c | 19 +++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
* driver
*
@@ -395,6 +412,8 @@ static int dwc2_driver_probe(struct platform_device
*dev)
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
(unsigned long)res->start, hsotg->regs);
+ hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg);
+
retval = dwc2_lowlevel_hw_init(hsotg);
if (retval)
return retval;
--
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index ae8534b..cc9c93a 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -857,6 +857,7 @@ struct dwc2_hregs_backup {
* @gr_backup: Backup of global registers during suspend
* @dr_backup: Backup of device registers during suspend
* @hr_backup: Backup of host registers during suspend
+ * @needs_byte_swap: Specifies whether the opposite endianness.
*
* These are for host mode:
*
@@ -1046,6 +1047,7 @@ struct dwc2_hsotg {
struct dentry *debug_root;
struct debugfs_regset32 *regset;
+ bool needs_byte_swap;
/* DWC OTG HW Release versions */
#define DWC2_CORE_REV_2_71a 0x4f54271a
@@ -1164,12 +1166,21 @@ struct dwc2_hsotg {
/* Normal architectures just use readl/write */
static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
{
- return readl(hsotg->regs + offset);
+ u32 val;
+
+ val = readl(hsotg->regs + offset);
+ if (hsotg->needs_byte_swap)
+ return swab32(val);
+ else
+ return val;
}
static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32
offset)
{
- writel(value, hsotg->regs + offset);
+ if (hsotg->needs_byte_swap)
+ writel(swab32(value), hsotg->regs + offset);
+ else
+ writel(value, hsotg->regs + offset);
#ifdef DWC2_LOG_WRITES
pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset);
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 4c08195..9a53a58 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -353,6 +353,23 @@ static void dwc2_driver_shutdown(struct
platform_device *dev)
}
/**
+ * dwc2_check_core_endianness() - Returns true if core and AHB have
+ * opposite endianness.
+ * @hsotg: Programming view of the DWC_otg controller.
+ */
+static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg)
+{
+ u32 snpsid;
+
+ snpsid = ioread32(hsotg->regs + GSNPSID);
+ if ((snpsid & GSNPSID_ID_MASK) == DWC2_OTG_ID ||
+ (snpsid & GSNPSID_ID_MASK) == DWC2_FS_IOT_ID ||
+ (snpsid & GSNPSID_ID_MASK) == DWC2_HS_IOT_ID)
+ return false;
+ return true;
+}
+
+/**
* dwc2_driver_probe() - Called when the DWC_otg core is bound to the
DWC_otg
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-27 7:05 Felipe Balbi
0 siblings, 0 replies; 8+ messages in thread
From: Felipe Balbi @ 2018-07-27 7:05 UTC (permalink / raw)
To: Andy Shevchenko, Gevorg Sahakyan
Cc: Greg Kroah-Hartman, Minas Harutyunyan, USB, John Youn
Andy Shevchenko <andy.shevchenko@gmail.com> writes:
> On Thu, Jul 26, 2018 at 5:01 PM, Gevorg Sahakyan
> <Gevorg.Sahakyan@synopsys.com> wrote:
>> Declared dwc2_check_core_endianness() function for dynamicly check
>> core endianness.
>> Added needs_byte_swap flag to hsotg structure, and depending on
>> flag swap value inside dwc2_readl/writel functions.
>
>> +#define swap32(x) (\
>> + {typeof(x) x_ = (x); \
>> + (((u32)(x_) << 24) & (u32)0xFF000000) | \
>> + (((u32)(x_) << 8) & (u32)0x00FF0000) | \
>> + (((u32)(x_) >> 8) & (u32)0x0000FF00) | \
>> + (((u32)(x_) >> 24) & (u32)0x000000FF); })
>
> What's wrong with swab32() ?
indeed. That's a reimplementation of swab32. Gevorg, care to fix this? I
have pushed patches 1 and 2.
BTW, make sure to send series as a series of patches where patches 2+
come as replies to patch 1. Your series are not showing up as threads.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-26 15:29 Andy Shevchenko
0 siblings, 0 replies; 8+ messages in thread
From: Andy Shevchenko @ 2018-07-26 15:29 UTC (permalink / raw)
To: Gevorg Sahakyan
Cc: Felipe Balbi, Greg Kroah-Hartman, Minas Harutyunyan, USB, John Youn
On Thu, Jul 26, 2018 at 5:01 PM, Gevorg Sahakyan
<Gevorg.Sahakyan@synopsys.com> wrote:
> Declared dwc2_check_core_endianness() function for dynamicly check
> core endianness.
> Added needs_byte_swap flag to hsotg structure, and depending on
> flag swap value inside dwc2_readl/writel functions.
> +#define swap32(x) (\
> + {typeof(x) x_ = (x); \
> + (((u32)(x_) << 24) & (u32)0xFF000000) | \
> + (((u32)(x_) << 8) & (u32)0x00FF0000) | \
> + (((u32)(x_) >> 8) & (u32)0x0000FF00) | \
> + (((u32)(x_) >> 24) & (u32)0x000000FF); })
What's wrong with swab32() ?
^ permalink raw reply [flat|nested] 8+ messages in thread
* [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic.
@ 2018-07-26 14:01 Gevorg Sahakyan
0 siblings, 0 replies; 8+ messages in thread
From: Gevorg Sahakyan @ 2018-07-26 14:01 UTC (permalink / raw)
To: Felipe Balbi, Greg Kroah-Hartman, Minas Harutyunyan, linux-usb
Cc: John Youn, Gevorg Sahakyan
Declared dwc2_check_core_endianness() function for dynamicly check
core endianness.
Added needs_byte_swap flag to hsotg structure, and depending on
flag swap value inside dwc2_readl/writel functions.
Signed-off-by: Gevorg Sahakyan <sahakyan@synopsys.com>
---
drivers/usb/dwc2/core.h | 22 ++++++++++++++++++++--
drivers/usb/dwc2/platform.c | 19 +++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index ae8534b..b8a0beb 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -96,6 +96,13 @@ static const char * const dwc2_hsotg_supply_names[] = {
*/
#define EP0_MPS_LIMIT 64
+#define swap32(x) (\
+ {typeof(x) x_ = (x); \
+ (((u32)(x_) << 24) & (u32)0xFF000000) | \
+ (((u32)(x_) << 8) & (u32)0x00FF0000) | \
+ (((u32)(x_) >> 8) & (u32)0x0000FF00) | \
+ (((u32)(x_) >> 24) & (u32)0x000000FF); })
+
struct dwc2_hsotg;
struct dwc2_hsotg_req;
@@ -857,6 +864,7 @@ struct dwc2_hregs_backup {
* @gr_backup: Backup of global registers during suspend
* @dr_backup: Backup of device registers during suspend
* @hr_backup: Backup of host registers during suspend
+ * @needs_byte_swap: Specifies whether the opposite endianness.
*
* These are for host mode:
*
@@ -1046,6 +1054,7 @@ struct dwc2_hsotg {
struct dentry *debug_root;
struct debugfs_regset32 *regset;
+ bool needs_byte_swap;
/* DWC OTG HW Release versions */
#define DWC2_CORE_REV_2_71a 0x4f54271a
@@ -1164,12 +1173,21 @@ struct dwc2_hsotg {
/* Normal architectures just use readl/write */
static inline u32 dwc2_readl(struct dwc2_hsotg *hsotg, u32 offset)
{
- return readl(hsotg->regs + offset);
+ u32 val;
+
+ val = readl(hsotg->regs + offset);
+ if (hsotg->needs_byte_swap)
+ return swap32(val);
+ else
+ return val;
}
static inline void dwc2_writel(struct dwc2_hsotg *hsotg, u32 value, u32 offset)
{
- writel(value, hsotg->regs + offset);
+ if (hsotg->needs_byte_swap)
+ writel(swap32(value), hsotg->regs + offset);
+ else
+ writel(value, hsotg->regs + offset);
#ifdef DWC2_LOG_WRITES
pr_info("info:: wrote %08x to %p\n", value, hsotg->regs + offset);
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 4c08195..9a53a58 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -353,6 +353,23 @@ static void dwc2_driver_shutdown(struct platform_device *dev)
}
/**
+ * dwc2_check_core_endianness() - Returns true if core and AHB have
+ * opposite endianness.
+ * @hsotg: Programming view of the DWC_otg controller.
+ */
+static bool dwc2_check_core_endianness(struct dwc2_hsotg *hsotg)
+{
+ u32 snpsid;
+
+ snpsid = ioread32(hsotg->regs + GSNPSID);
+ if ((snpsid & GSNPSID_ID_MASK) == DWC2_OTG_ID ||
+ (snpsid & GSNPSID_ID_MASK) == DWC2_FS_IOT_ID ||
+ (snpsid & GSNPSID_ID_MASK) == DWC2_HS_IOT_ID)
+ return false;
+ return true;
+}
+
+/**
* dwc2_driver_probe() - Called when the DWC_otg core is bound to the DWC_otg
* driver
*
@@ -395,6 +412,8 @@ static int dwc2_driver_probe(struct platform_device *dev)
dev_dbg(&dev->dev, "mapped PA %08lx to VA %p\n",
(unsigned long)res->start, hsotg->regs);
+ hsotg->needs_byte_swap = dwc2_check_core_endianness(hsotg);
+
retval = dwc2_lowlevel_hw_init(hsotg);
if (retval)
return retval;
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2018-07-27 10:00 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-27 8:19 [v2,3/3] usb: dwc2: Make dwc2_readl/writel functions endianness-agnostic Felipe Balbi
-- strict thread matches above, loose matches on Subject: below --
2018-07-27 10:00 Felipe Balbi
2018-07-27 8:41 Grigor Tovmasyan
2018-07-27 8:26 Gevorg Sahakyan
2018-07-27 8:19 Gevorg Sahakyan
2018-07-27 7:05 Felipe Balbi
2018-07-26 15:29 Andy Shevchenko
2018-07-26 14:01 Gevorg Sahakyan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.