Re: [PATCH 1/3] watchdog: Select CONFIG_PARAMETER

2020-01-22 Thread Sascha Hauer
On Wed, Jan 22, 2020 at 10:39:07AM +0100, Christian Eggers wrote:
> Hi Sascha,
> 
> Am Mittwoch, 22. Januar 2020, 09:21:15 CET schrieb Sascha Hauer:
> > Hi Christian,
> >
> > > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > > index 45dd41a2a..34b7fea39 100644
> > > --- a/drivers/watchdog/Kconfig
> > > +++ b/drivers/watchdog/Kconfig
> > > @@ -4,6 +4,7 @@ config WATCHDOG_IMX_RESET_SOURCE
> > >
> > >  menuconfig WATCHDOG
> > >
> > > bool "Watchdog support"
> > >
> > > +   select PARAMETER
> >
> > I think this goes into the wrong direction. With CONFIG_PARAMETER
> > enabled we get support for adjusting device parameters from the shell.
> > In environments without shell support parameter support is not needed.
> > For example the watchdog C API doesn't need parameter support and is
> > still usable.
> >
> > The static inline wrappers for dev_add_param_* should return NULL
> > instead of returning ERR_PTR(-ENOSYS).
> 
> initially I came to the same result. But previous commits to param.h went in
> the opposite direction:
> 
> > 03b59bdb64 ("paramter: The dev_add_param_*() return ERR_PTR(), change
> > no-ops") to return ERR_PTR(-ENOSYS) instead of NULL

Shouldn't have merged this one as it lacks an explanation why this has
been done. Marc, do you have an idea what the motivation for this patch
was?

> >
> > Signed-off-by: Marc Kleine-Budde 
> > Signed-off-by: Sascha Hauer 
> 
> and
> 
> > c5d95eb4c7 ("param: make parameter functions more consistent")
> >
> > Signed-off-by: Sascha Hauer 
> 
> Most of the callers of dev_add_param*()  don't care about the returned param
> pointer at all. Some are checking against PTR_ERR() which would not be hit if
> returning NULL (this is what we want).
> 
> A few callers have to changed if a NULL pointer can be returned:
> - __nvvar_add()

nvvar doesn't really make sense without CONFIG_PARAMETER enabled. There
currently is no dependency between these options, but probably there
should be.

> - state_string_create()  stores the result in state_string::param, but seems
> to be used nowhere
> - mci_register() dito for mci::param_probe
> - state_uint8_create() dito for state_uint32::param
> - state_uint32_create() dito
> 
> For me it looks reasonable to return a NULL pointer if CONFIG_PARAMETER is not
> set (as you suggested). Only __nvvar_add() needs slight changes and I would
> remove needless storage of param in structs state_string, mci and
> state_uint32.
> 
> Shall I start?

Let's wait for Marc if he has an idea why we introduced 03b59bdb64, but
otherwise yes, this sounds like a good plan.


Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [yocto] #yocto bootchooser: Cannot get state 'state'

2020-01-22 Thread Robert ber...@yocto.user

Hi,

Did you install the SDK?

Did you run the environment script?


make: /path/to/your/yocto/toolchain/bin/arm--linux-gnueabihf-gcc: Kommando 
nicht gefunden
   LEX scripts/kconfig/lexer.lex.c
/bin/sh: 1: flex: not found



   YACCscripts/kconfig/parser.tab.h
/bin/sh: 1: bison: not found


flex and bison seem to be missing as well.

Regards,

Robert

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[RFC PATCH 8/9] usb: dwc2: gadget: Configure fifo size

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/core.c | 86 +
 1 file changed, 86 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 5376a3586..ebb555f0d 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -87,6 +87,87 @@ void dwc2_set_param_phy_utmi_width(struct dwc2 *dwc2)
dwc2->params.phy_utmi_width = val;
 }
 
+/**
+ * dwc2_hsotg_tx_fifo_count - return count of TX FIFOs in device mode
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ */
+static int dwc2_tx_fifo_count(struct dwc2 *dwc2)
+{
+   if (dwc2->hw_params.en_multiple_tx_fifo)
+   /* In dedicated FIFO mode we need count of IN EPs */
+   return dwc2->hw_params.num_dev_in_eps;
+   else
+   /* In shared FIFO mode we need count of Periodic IN EPs */
+   return dwc2->hw_params.num_dev_perio_in_ep;
+}
+
+/**
+ * dwc2_hsotg_tx_fifo_total_depth - return total FIFO depth available for
+ * device mode TX FIFOs
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ */
+static int dwc2_tx_fifo_total_depth(struct dwc2 *dwc2)
+{
+   int addr;
+   int tx_addr_max;
+   u32 np_tx_fifo_size;
+
+   np_tx_fifo_size = min_t(u32, dwc2->hw_params.dev_nperio_tx_fifo_size,
+   dwc2->params.g_np_tx_fifo_size);
+
+   /* Get Endpoint Info Control block size in DWORDs. */
+   tx_addr_max = dwc2->hw_params.total_fifo_size;
+
+   addr = dwc2->params.g_rx_fifo_size + np_tx_fifo_size;
+
+   if (tx_addr_max <= addr)
+   return 0;
+
+   return tx_addr_max - addr;
+}
+
+static void dwc2_set_param_tx_fifo_sizes(struct dwc2 *dwc2)
+{
+   struct dwc2_core_params *p = >params;
+   int count;
+   int depth;
+   int i;
+
+   count = dwc2_tx_fifo_count(dwc2);
+
+   depth = dwc2_tx_fifo_total_depth(dwc2);
+   if (count)
+   depth /= count;
+
+   memset(p->g_tx_fifo_size, 0, sizeof(p->g_tx_fifo_size));
+   for (i = 1; i <= count; i++)
+   p->g_tx_fifo_size[i] = depth;
+}
+
+static void dwc2_set_param_fifo_sizes(struct dwc2 *dwc2)
+{
+   struct dwc2_hw_params *hw = >hw_params;
+   struct dwc2_core_params *p = >params;
+   u32 total_fifo_size = dwc2->hw_params.total_fifo_size;
+   u32 max_np_tx_fifo_size = hw->dev_nperio_tx_fifo_size;
+   u32 max_rx_fifo_size = hw->rx_fifo_size;
+   int count;
+   int depth;
+   int i;
+
+   count = dwc2_tx_fifo_count(dwc2);
+
+   depth = (total_fifo_size & ~0x7f) / (count * 3 + 8);
+   p->g_rx_fifo_size = depth * count * 2;
+   p->g_np_tx_fifo_size = depth * 8;
+
+   for (i = 1; i <= count; i++)
+   p->g_tx_fifo_size[i] = depth;
+
+}
+
 /**
  * dwc2_set_default_params() - Set all core parameters to their
  * auto-detected default values.
@@ -138,6 +219,11 @@ void dwc2_set_default_params(struct dwc2 *dwc2)
p->host_nperio_tx_fifo_size = hw->host_nperio_tx_fifo_size;
p->host_perio_tx_fifo_size = hw->host_perio_tx_fifo_size;
}
+
+   if ((dwc2->dr_mode == USB_DR_MODE_PERIPHERAL) ||
+   (dwc2->dr_mode == USB_DR_MODE_OTG)) {
+   dwc2_set_param_fifo_sizes(dwc2);
+   }
 }
 
 int dwc2_core_snpsid(struct dwc2 *dwc2)
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[RFC PATCH 5/9] usb: dwc2: Add function to flush a tx fifo

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/core.c | 33 +
 drivers/usb/dwc2/dwc2.h |  1 +
 2 files changed, 34 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 1812de034..90e7c0116 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -294,6 +294,39 @@ void dwc2_flush_all_fifo(struct dwc2 *dwc2)
udelay(1);
 }
 
+/**
+ * dwc2_flush_tx_fifo() - Flushes a Tx FIFO
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ * @idx: The fifo index (0..15)
+ */
+void dwc2_flush_tx_fifo(struct dwc2 *dwc2, const int idx)
+{
+   u32 greset;
+
+   if (idx > 15)
+   return;
+
+   dwc2_dbg(dwc2, "Flush Tx FIFO %d\n", idx);
+
+   /* Wait for AHB master IDLE state */
+   if (dwc2_wait_bit_set(dwc2, GRSTCTL, GRSTCTL_AHBIDLE, 1)) {
+   dwc2_warn(dwc2, "%s: Timeout waiting for AHB Idle\n", __func__);
+   return;
+   }
+
+   greset = GRSTCTL_TXFFLSH;
+   greset |= GRSTCTL_TXFNUM(idx) & GRSTCTL_TXFNUM_MASK;
+   dwc2_writel(dwc2, greset, GRSTCTL);
+
+   if (dwc2_wait_bit_clear(dwc2, GRSTCTL, GRSTCTL_TXFFLSH, 1))
+   dwc2_warn(dwc2, "%s: Timeout flushing tx fifo (GRSTCTL=%08x)\n",
+__func__, dwc2_readl(dwc2, GRSTCTL));
+
+   /* Wait for at least 3 PHY Clocks */
+   udelay(1);
+}
+
 static int dwc2_fs_phy_init(struct dwc2 *dwc2, bool select_phy)
 {
u32 usbcfg, ggpio, i2cctl;
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 35ba00660..1141573bb 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -17,6 +17,7 @@ void dwc2_get_hwparams(struct dwc2 *dwc2);
 
 void dwc2_init_fs_ls_pclk_sel(struct dwc2 *dwc2);
 void dwc2_flush_all_fifo(struct dwc2 *dwc2);
+void dwc2_flush_tx_fifo(struct dwc2 *dwc2, const int idx);
 
 int dwc2_phy_init(struct dwc2 *dwc2, bool select_phy);
 int dwc2_gahbcfg_init(struct dwc2 *dwc2);
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[RFC PATCH 7/9] usb: dwc2: Add getter for gadget fifo hwparams

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/core.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 90e7c0116..5376a3586 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -167,6 +167,33 @@ int dwc2_core_snpsid(struct dwc2 *dwc2)
return 0;
 }
 
+static int dwc2_num_dev_tx_fifo(struct dwc2 *dwc2)
+{
+   if (dwc2->hw_params.en_multiple_tx_fifo)
+   /* In dedicated FIFO mode we need count of IN EPs */
+   return dwc2->hw_params.num_dev_in_eps;
+   else
+   /* In shared FIFO mode we need count of Periodic IN EPs */
+   return dwc2->hw_params.num_dev_perio_in_ep;
+}
+
+static void dwc2_get_dev_hwparams(struct dwc2 *dwc2)
+{
+   struct dwc2_hw_params *hw = >hw_params;
+   u32 size;
+   int num, i;
+
+   size = FIFOSIZE_DEPTH_GET(dwc2_readl(dwc2, GNPTXFSIZ));
+   hw->dev_nperio_tx_fifo_size = size;
+
+   num = dwc2_num_dev_tx_fifo(dwc2);
+
+   for (i = 1; i <= num; i++) {
+   size = FIFOSIZE_DEPTH_GET(dwc2_readl(dwc2, DPTXFSIZN(i)));
+   hw->g_tx_fifo_size[i] = size;
+   }
+}
+
 /**
  * During device initialization, read various hardware configuration
  * registers and interpret the contents.
@@ -243,6 +270,8 @@ void dwc2_get_hwparams(struct dwc2 *dwc2)
/* fifo sizes */
hw->rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
GRXFSIZ_DEPTH_SHIFT;
+
+   dwc2_get_dev_hwparams(dwc2);
 }
 
 /*
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[RFC PATCH 9/9] usb: dwc2: Add gadget driver

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/Makefile |2 +-
 drivers/usb/dwc2/core.h   |8 +-
 drivers/usb/dwc2/dwc2.c   |2 +
 drivers/usb/dwc2/dwc2.h   |2 +
 drivers/usb/dwc2/gadget.c | 2668 +
 drivers/usb/dwc2/regs.h   |1 +
 6 files changed, 2681 insertions(+), 2 deletions(-)
 create mode 100644 drivers/usb/dwc2/gadget.c

diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile
index 3b922c282..6d62a0a40 100644
--- a/drivers/usb/dwc2/Makefile
+++ b/drivers/usb/dwc2/Makefile
@@ -1 +1 @@
-obj-$(CONFIG_USB_DWC2) += dwc2.o core.o host.o rhub.o
+obj-$(CONFIG_USB_DWC2) += dwc2.o core.o host.o rhub.o gadget.o
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index e25674558..d22a0300f 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -476,7 +476,6 @@ struct dwc2 {
void __iomem *regs;
int root_hub_devnum;
 
-   int num_eps;
struct dwc2_ep *eps_in[MAX_ENDPOINT];
struct dwc2_ep *eps_out[MAX_ENDPOINT];
struct usb_request *ctrl_req;
@@ -487,6 +486,13 @@ struct dwc2 {
 
enum usb_dr_mode dr_mode;
enum usb_otg_state op_state;
+   u16 frame_number;
+   int num_eps;
+   u32 fifo_map;
+
+   unsigned int dedicated_fifos:1;
+   unsigned int enabled:1;
+   unsigned int connected:1;
 };
 
 #define host_to_dwc2(ptr) container_of(ptr, struct dwc2, host)
diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 1df393e77..753f64c0b 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -76,6 +76,8 @@ static int dwc2_probe(struct device_d *dev)
host->submit_int_msg = dwc2_submit_int_msg;
retval = usb_register_host(host);
 
+   dwc2_gadget_init(dwc2);
+
 error:
return retval;
 }
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 1141573bb..6fd81659c 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -41,3 +41,5 @@ int dwc2_submit_roothub(struct dwc2 *dwc2, struct usb_device 
*dev,
unsigned long pipe, void *buf, int len,
struct devrequest *setup);
 
+/* Gadget functions */
+int dwc2_gadget_init(struct dwc2 *dwc2);
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
new file mode 100644
index 0..44781f4cc
--- /dev/null
+++ b/drivers/usb/dwc2/gadget.c
@@ -0,0 +1,2668 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include 
+#include 
+#include "dwc2.h"
+
+#define to_dwc2 gadget_to_dwc2
+#define dwc2_set_bit(d, r, b) dwc2_writel(d, (b) | dwc2_readl(d, r), r)
+#define dwc2_clear_bit(d, r, b) dwc2_writel(d, ~(b) & dwc2_readl(d, r), r)
+
+#define spin_lock(lock)
+#define spin_unlock(lock)
+#define local_irq_save(flags)
+#define local_irq_restore(flags)
+#define spin_lock_irqsave(lock, flags)
+#define spin_unlock_irqrestore(lock, flags)
+
+static void kill_all_requests(struct dwc2 *dwc2, struct dwc2_ep *ep, int 
result);
+
+static inline struct dwc2_ep *index_to_ep(struct dwc2 *dwc2,
+ unsigned int ep, int in)
+{
+   if (ep >= MAX_ENDPOINT)
+   return NULL;
+   if (in)
+   return dwc2->eps_in[ep];
+   else
+   return dwc2->eps_out[ep];
+}
+
+static inline int using_dma(struct dwc2 *dwc2)
+{
+   /* Only buffer dma is supported */
+   return 1;
+}
+
+static void dwc2_dcfg_set_addr(struct dwc2 *dwc2, int addr)
+{
+   u32 dcfg = dwc2_readl(dwc2, DCFG);
+
+   dcfg &= ~DCFG_DEVADDR_MASK;
+   dcfg |= (addr << DCFG_DEVADDR_SHIFT) & DCFG_DEVADDR_MASK;
+   dwc2_writel(dwc2, dcfg, DCFG);
+}
+
+/**
+ * dwc2_hsotg_ctrl_epint - enable/disable an endpoint irq
+ * @hsotg: The device state
+ * @ep: The endpoint index
+ * @dir_in: True if direction is in.
+ * @en: The enable value, true to enable
+ *
+ * Set or clear the mask for an individual endpoint's interrupt
+ * request.
+ */
+static void dwc2_hsotg_ctrl_epint(struct dwc2 *dwc2,
+ unsigned int ep, unsigned int dir_in,
+unsigned int en)
+{
+   unsigned long flags;
+   u32 bit = 1 << ep;
+   u32 daint;
+
+   if (!dir_in)
+   bit <<= 16;
+
+   local_irq_save(flags);
+   daint = dwc2_readl(dwc2, DAINTMSK);
+   if (en)
+   daint |= bit;
+   else
+   daint &= ~bit;
+   dwc2_writel(dwc2, daint, DAINTMSK);
+   local_irq_restore(flags);
+
+}
+
+/**
+ * get_ep_head - return the first request on the endpoint
+ * @hs_ep: The controller endpoint to get
+ *
+ * Get the first request on the endpoint.
+ */
+static struct dwc2_request *get_ep_head(struct dwc2_ep *hs_ep)
+{
+   return list_first_entry_or_null(_ep->queue, struct dwc2_request,
+   queue);
+}
+
+/**
+ * get_ep_limit - get the maximum data legnth for this endpoint
+ * @hs_ep: The endpoint
+ *
+ * Return the maximum data that 

[RFC PATCH 6/9] usb: dwc2: Add structure for gadget driver

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/core.h | 52 +
 1 file changed, 52 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 56d5cbbfb..e25674558 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -421,6 +421,49 @@ enum usb_otg_state {
OTG_STATE_B_PERIPHERAL,
 };
 
+struct dwc2_ep {
+   struct usb_ep ep;
+   struct dwc2 *dwc2;
+   struct list_head queue;
+   struct dwc2_request *req;
+   char name[8];
+
+   unsigned intsize_loaded;
+   unsigned intlast_load;
+   unsigned short  fifo_size;
+   unsigned short  fifo_index;
+
+   u8 dir_in;
+   u8 epnum;
+   u8 mc;
+   u16 interval;
+
+   unsigned inthalted:1;
+   unsigned intperiodic:1;
+   unsigned intisochronous:1;
+   unsigned intsend_zlp:1;
+   unsigned inttarget_frame;
+#define TARGET_FRAME_INITIAL   0x
+   boolframe_overrun;
+};
+
+struct dwc2_request {
+   struct usb_request req;
+   struct list_head queue;
+};
+
+/* Gadget ep0 states */
+enum dwc2_ep0_state {
+   DWC2_EP0_SETUP,
+   DWC2_EP0_DATA_IN,
+   DWC2_EP0_DATA_OUT,
+   DWC2_EP0_STATUS_IN,
+   DWC2_EP0_STATUS_OUT,
+};
+
+/* Size of control and EP0 buffers */
+#define DWC2_CTRL_BUFF_SIZE 8
+
 struct dwc2 {
struct device_d *dev;
struct usb_host host;
@@ -433,6 +476,15 @@ struct dwc2 {
void __iomem *regs;
int root_hub_devnum;
 
+   int num_eps;
+   struct dwc2_ep *eps_in[MAX_ENDPOINT];
+   struct dwc2_ep *eps_out[MAX_ENDPOINT];
+   struct usb_request *ctrl_req;
+   void *ep0_buff;
+   void *ctrl_buff;
+   enum dwc2_ep0_state ep0_state;
+   struct usb_gadget_driver *driver;
+
enum usb_dr_mode dr_mode;
enum usb_otg_state op_state;
 };
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[RFC PATCH 4/9] usb: dwc2: Add otg state

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/core.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 0c89217c5..56d5cbbfb 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -416,6 +416,11 @@ struct dwc2_hw_params {
 #define MAX_DEVICE 16
 #define MAX_ENDPOINT DWC2_MAX_EPS_CHANNELS
 
+enum usb_otg_state {
+   OTG_STATE_A_HOST,
+   OTG_STATE_B_PERIPHERAL,
+};
+
 struct dwc2 {
struct device_d *dev;
struct usb_host host;
@@ -429,6 +434,7 @@ struct dwc2 {
int root_hub_devnum;
 
enum usb_dr_mode dr_mode;
+   enum usb_otg_state op_state;
 };
 
 #define host_to_dwc2(ptr) container_of(ptr, struct dwc2, host)
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[RFC PATCH 3/9] usb: Update uses of usb_endpoint_maxp

2020-01-22 Thread Jules Maselbas
Now usb_endpoint_maxp only returns the 11 lowest bits, it does no
longer include the mult bits. And such functions that uses the mult
bits must be updated to uses the usb_endpoint_maxp_mult function.

Signed-off-by: Jules Maselbas 
---
 drivers/usb/gadget/epautoconf.c |  2 +-
 drivers/usb/musb/musb_gadget.c  | 12 
 drivers/usb/musb/musb_host.c|  3 +--
 3 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index ced568921..c4c4a5672 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -132,7 +132,7 @@ ep_matches (
 * where it's an output parameter representing the full speed limit.
 * the usb spec fixes high speed bulk maxpacket at 512 bytes.
 */
-   max = 0x7ff & usb_endpoint_maxp(desc);
+   max = usb_endpoint_maxp(desc);
switch (type) {
case USB_ENDPOINT_XFER_INT:
/* INT:  limit 64 bytes full speed, 1024 high/super speed */
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index fc5cfb13f..c5e46cfe0 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -443,8 +443,10 @@ static int musb_gadget_enable(struct usb_ep *ep,
goto fail;
 
/* REVISIT this rules out high bandwidth periodic transfers */
-   tmp = usb_endpoint_maxp(desc);
-   if (tmp & ~0x07ff) {
+   musb_ep->packet_sz = usb_endpoint_maxp(desc);
+   musb_ep->hb_mult = usb_endpoint_maxp_mult(desc);
+   tmp = musb_ep->packet_sz * musb_ep->hb_mult;
+   if (musb_ep->hb_mult > 1) {
int ok;
 
if (usb_endpoint_dir_in(desc))
@@ -456,14 +458,8 @@ static int musb_gadget_enable(struct usb_ep *ep,
dev_dbg(musb->controller, "no support for high 
bandwidth ISO\n");
goto fail;
}
-   musb_ep->hb_mult = (tmp >> 11) & 3;
-   } else {
-   musb_ep->hb_mult = 0;
}
 
-   musb_ep->packet_sz = tmp & 0x7ff;
-   tmp = musb_ep->packet_sz * (musb_ep->hb_mult + 1);
-
/* enable the interrupts for the endpoint, set the endpoint
 * packet size (or fail), set the mode, clear the fifo
 */
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 68d819af2..11fde729a 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -1493,7 +1493,7 @@ int musb_urb_enqueue(
 * Some musb cores don't support high bandwidth ISO transfers; and
 * we don't (yet!) support high bandwidth interrupt transfers.
 */
-   qh->hb_mult = 1 + ((qh->maxpacket >> 11) & 0x03);
+   qh->hb_mult = usb_endpoint_maxp_mult(epd);
if (qh->hb_mult > 1) {
int ok = (qh->type == USB_ENDPOINT_XFER_ISOC);
 
@@ -1504,7 +1504,6 @@ int musb_urb_enqueue(
ret = -EMSGSIZE;
goto done;
}
-   qh->maxpacket &= 0x7ff;
}
 
qh->epnum = usb_endpoint_num(epd);
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[RFC PATCH 0/9] usb: Add dwc2 gadget driver

2020-01-22 Thread Jules Maselbas
This driver is a slimed down version of Linux's dwc2 gadget driver.
It only support direct dma (not descriptor based dma) and does not
support direct buffer (aka slave mode) although this could be nice
to have.

This patchset also backport two commits from Linux that change the
behavior of usb_endpint_maxp() to only return the packet size, the
other information is now available in usb_endpoint_maxp_mult().
At the time I write this lines, I notice that the mult information
is only needed for isochronous transfers, which are not supported
by this driver...

Once again this driver as only be tested on our custom SoC, this is
still a work in progress.

Any feedback are welcome, cheers.
Jules

---

Jules Maselbas (9):
  BACKPORT: usb: Add helper to extract bits 12:11 of wMaxPacketize
  BACKPORT: usb: ch9: make usb_endpoint_maxp() return only packet size
  usb: Update uses of usb_endpoint_maxp
  usb: dwc2: Add otg state
  usb: dwc2: Add function to flush a tx fifo
  usb: dwc2: Add structure for gadget driver
  usb: dwc2: Add getter for gadget fifo hwparams
  usb: dwc2: gadget: Configure fifo size
  usb: dwc2: Add gadget driver

 drivers/usb/dwc2/Makefile   |2 +-
 drivers/usb/dwc2/core.c |  148 ++
 drivers/usb/dwc2/core.h |   64 +
 drivers/usb/dwc2/dwc2.c |2 +
 drivers/usb/dwc2/dwc2.h |3 +
 drivers/usb/dwc2/gadget.c   | 2668 +++
 drivers/usb/dwc2/regs.h |1 +
 drivers/usb/gadget/epautoconf.c |2 +-
 drivers/usb/musb/musb_gadget.c  |   12 +-
 drivers/usb/musb/musb_host.c|3 +-
 include/usb/ch9.h   |   25 +-
 11 files changed, 2916 insertions(+), 14 deletions(-)
 create mode 100644 drivers/usb/dwc2/gadget.c

-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 3/7] usb: dwc2: host: Rework roothub interface

2020-01-22 Thread Jules Maselbas
Roothub requests are now decoded in one place.

Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/dwc2.h |   2 +-
 drivers/usb/dwc2/host.c |   4 +-
 drivers/usb/dwc2/rhub.c | 519 +++-
 3 files changed, 245 insertions(+), 280 deletions(-)

diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 60cdca520..35ba00660 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -36,7 +36,7 @@ int dwc2_submit_int_msg(struct usb_device *dev, unsigned long 
pipe,
void *buffer, int transfer_len, int interval);
 int dwc2_host_init(struct usb_host *host);
 
-int dwc2_submit_rh_msg(struct dwc2 *dwc2, struct usb_device *dev,
+int dwc2_submit_roothub(struct dwc2 *dwc2, struct usb_device *dev,
unsigned long pipe, void *buf, int len,
struct devrequest *setup);
 
diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
index d66c70fbc..61c29910e 100644
--- a/drivers/usb/dwc2/host.c
+++ b/drivers/usb/dwc2/host.c
@@ -326,9 +326,9 @@ int dwc2_submit_control_msg(struct usb_device *udev,
int status_direction;
 
if (devnum == dwc2->root_hub_devnum) {
-   udev->status = 0;
udev->speed = USB_SPEED_HIGH;
-   return dwc2_submit_rh_msg(dwc2, udev, pipe, buffer, len, setup);
+   ret = dwc2_submit_roothub(dwc2, udev, pipe, buffer, len, setup);
+   return ret;
}
 
/* SETUP stage */
diff --git a/drivers/usb/dwc2/rhub.c b/drivers/usb/dwc2/rhub.c
index 86552da99..cc733f34e 100644
--- a/drivers/usb/dwc2/rhub.c
+++ b/drivers/usb/dwc2/rhub.c
@@ -7,7 +7,7 @@ static struct descriptor {
struct usb_config_descriptor config;
struct usb_interface_descriptor interface;
struct usb_endpoint_descriptor endpoint;
-}  __attribute__ ((packed)) descriptor = {
+}  __packed descriptor = {
.hub = {
.bLength= USB_DT_HUB_NONVAR_SIZE +
  ((USB_MAXCHILDREN + 1 + 7) / 8),
@@ -22,7 +22,7 @@ static struct descriptor {
.device = {
.bLength= USB_DT_DEVICE_SIZE,
.bDescriptorType= USB_DT_DEVICE,
-   .bcdUSB = __constant_cpu_to_le16(2), /* v2.0 */
+   .bcdUSB = cpu_to_le16(2), /* v2.0 */
.bDeviceClass   = USB_CLASS_HUB,
.bDeviceSubClass= 0,
.bDeviceProtocol= USB_HUB_PR_HS_NO_TT,
@@ -38,7 +38,7 @@ static struct descriptor {
.config = {
.bLength= USB_DT_CONFIG_SIZE,
.bDescriptorType= USB_DT_CONFIG,
-   .wTotalLength   = __constant_cpu_to_le16(
+   .wTotalLength   = cpu_to_le16(
USB_DT_CONFIG_SIZE +
USB_DT_INTERFACE_SIZE +
USB_DT_ENDPOINT_SIZE),
@@ -64,356 +64,321 @@ static struct descriptor {
.bDescriptorType= USB_DT_ENDPOINT,
.bEndpointAddress   = 1 | USB_DIR_IN, /* 0x81 */
.bmAttributes   = USB_ENDPOINT_XFER_INT,
-   .wMaxPacketSize = __constant_cpu_to_le16(
+   .wMaxPacketSize = cpu_to_le16(
(USB_MAXCHILDREN + 1 + 7) / 8),
.bInterval  = 255
},
 };
 
-static char *language_string = "\x09\x04";
-static char *vendor_string = "u-boot";
-static char *product_string = "DWC2 root hub";
-
-/*
- * DWC2 to USB API interface
- */
-static int dwc2_submit_rh_msg_in_status(struct dwc2 *dwc2,
-  struct usb_device *dev, void *buffer,
-  int txlen, struct devrequest *cmd)
+static int dwc2_get_port_status(struct dwc2 *dwc2, struct usb_device *dev,
+   void *buf, int len)
 {
struct usb_port_status *portsts;
-   uint32_t hprt0 = 0;
-   uint32_t port_status = 0;
-   uint32_t port_change = 0;
-   int len = 0;
+   uint32_t hprt0;
+   uint32_t status = 0;
+   uint32_t change = 0;
int speed;
 
-   switch (cmd->requesttype & (USB_TYPE_MASK | USB_RECIP_MASK)) {
-   case USB_TYPE_STANDARD | USB_RECIP_DEVICE:
-   *(uint16_t *)buffer = cpu_to_le16(1);
-   len = 2;
-   break;
-   case USB_TYPE_STANDARD | USB_RECIP_INTERFACE:
-   case USB_TYPE_STANDARD | USB_RECIP_ENDPOINT:
-   *(uint16_t *)buffer = cpu_to_le16(0);
-   len = 2;
-   break;
-   case USB_RT_HUB:/* USB_TYPE_CLASS | USB_RECIP_DEVICE */
-   *(uint32_t *)buffer = cpu_to_le32(0);
-   len = 4;
-   break;
-   case USB_RT_PORT:   /* 

[RFC PATCH 2/9] BACKPORT: usb: ch9: make usb_endpoint_maxp() return only packet size

2020-01-22 Thread Jules Maselbas
Now that we have a helper to gather periodic
endpoints' multiplier bits from wMaxPacketSize and
every driver is using it, we can safely make sure
that usb_endpoint_maxp() returns only bits 10:0 of
wMaxPacketSize which is where the actual packet size
lies.

(backported from linux commit abb621844f6a0c93bbc934f9a096752c4c1c5722)

Signed-off-by: Jules Maselbas 
---
 include/usb/ch9.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/usb/ch9.h b/include/usb/ch9.h
index fc6ec862c..5adabcaee 100644
--- a/include/usb/ch9.h
+++ b/include/usb/ch9.h
@@ -401,6 +401,7 @@ struct usb_endpoint_descriptor {
 #define USB_ENDPOINT_XFER_INT  3
 #define USB_ENDPOINT_MAX_ADJUSTABLE0x80
 
+#define USB_ENDPOINT_MAXP_MASK 0x07ff
 #define USB_EP_MAXP_MULT_SHIFT 11
 #define USB_EP_MAXP_MULT_MASK  (3 << USB_EP_MAXP_MULT_SHIFT)
 #define USB_EP_MAXP_MULT(m) \
@@ -620,11 +621,11 @@ usb_endpoint_maxp_mult(const struct 
usb_endpoint_descriptor *epd)
  * usb_endpoint_maxp - get endpoint's max packet size
  * @epd: endpoint to be checked
  *
- * Returns @epd's max packet
+ * Returns @epd's max packet bits [10:0]
  */
 static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
 {
-   return __le16_to_cpu(epd->wMaxPacketSize);
+   return __le16_to_cpu(epd->wMaxPacketSize) & USB_ENDPOINT_MAXP_MASK;
 }
 
 static inline int usb_endpoint_interrupt_type(
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 7/7] usb: dwc2: host: Rewrite dwc2_hc_init

2020-01-22 Thread Jules Maselbas
Removed the uses of a table to convert the usb endpoint type for
the controller.

Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/host.c | 47 +++--
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
index e6344ea41..cd087b11b 100644
--- a/drivers/usb/dwc2/host.c
+++ b/drivers/usb/dwc2/host.c
@@ -7,13 +7,6 @@
 /* Use only HC channel 0. */
 #define DWC2_HC_CHANNEL0
 
-static int dwc2_eptype[] = {
-   DXEPCTL_EPTYPE_ISO,
-   DXEPCTL_EPTYPE_INTERRUPT,
-   DXEPCTL_EPTYPE_CONTROL,
-   DXEPCTL_EPTYPE_BULK,
-};
-
 static int dwc2_do_split(struct dwc2 *dwc2, struct usb_device *dev)
 {
uint32_t hprt0 = dwc2_readl(dwc2, HPRT0);
@@ -80,15 +73,32 @@ static void dwc2_hc_enable_ints(struct dwc2 *dwc2, uint8_t 
hc)
  * @param regs Programming view of DWC2 controller
  * @param hc Information needed to initialize the host channel
  */
-static void dwc2_hc_init(struct dwc2 *dwc2, uint8_t hc,
-   struct usb_device *dev, uint8_t dev_addr, uint8_t ep_num,
-   uint8_t ep_is_in, uint32_t ep_type, uint16_t max_packet)
+static void dwc2_hc_init(struct dwc2 *dwc2, struct usb_device *dev, u8 hc,
+unsigned long pipe, int is_in)
 {
-   uint32_t hcchar = (dev_addr << HCCHAR_DEVADDR_SHIFT) |
- (ep_num << HCCHAR_EPNUM_SHIFT) |
- (ep_is_in ? HCCHAR_EPDIR : 0) |
- ep_type |
- (max_packet << HCCHAR_MPS_SHIFT);
+   int addr = usb_pipedevice(pipe);
+   int endp = usb_pipeendpoint(pipe);
+   int type = usb_pipetype(pipe);
+   int mps = usb_maxpacket(dev, pipe);
+   uint32_t hcchar = (addr << HCCHAR_DEVADDR_SHIFT) |
+ (endp << HCCHAR_EPNUM_SHIFT) |
+ (is_in ? HCCHAR_EPDIR : 0) |
+ (mps << HCCHAR_MPS_SHIFT);
+
+   switch (type) {
+   case PIPE_ISOCHRONOUS:
+   hcchar |= DXEPCTL_EPTYPE_ISO;
+   break;
+   case PIPE_INTERRUPT:
+   hcchar |= DXEPCTL_EPTYPE_INTERRUPT;
+   break;
+   case PIPE_CONTROL:
+   hcchar |= DXEPCTL_EPTYPE_CONTROL;
+   break;
+   case PIPE_BULK:
+   hcchar |= DXEPCTL_EPTYPE_BULK;
+   break;
+   }
 
if (dev->speed == USB_SPEED_LOW)
hcchar |= HCCHAR_LSPDDEV;
@@ -206,10 +216,7 @@ static int dwc2_submit_packet(struct dwc2 *dwc2, struct 
usb_device *dev,
  unsigned long pipe, u8 *pid, int in, void *buf,
  int len)
 {
-   int devnum = usb_pipedevice(pipe);
-   int ep = usb_pipeendpoint(pipe);
int mps = usb_maxpacket(dev, pipe);
-   int eptype = dwc2_eptype[usb_pipetype(pipe)];
int do_split = dwc2_do_split(dwc2, dev);
int complete_split = 0;
int done = 0;
@@ -230,7 +237,7 @@ static int dwc2_submit_packet(struct dwc2 *dwc2, struct 
usb_device *dev,
max_xfer_len = num_packets * mps;
 
/* Initialize channel */
-   dwc2_hc_init(dwc2, DWC2_HC_CHANNEL, dev, devnum, ep, in, eptype, mps);
+   dwc2_hc_init(dwc2, dev, DWC2_HC_CHANNEL, pipe, in);
 
/* Check if the target is a FS/LS device behind a HS hub */
if (do_split) {
@@ -261,7 +268,7 @@ static int dwc2_submit_packet(struct dwc2 *dwc2, struct 
usb_device *dev,
dwc2_writel(dwc2, hcsplt, HCSPLT(DWC2_HC_CHANNEL));
}
 
-   if (eptype == DXEPCTL_EPTYPE_INTERRUPT) {
+   if (usb_pipeint(pipe)) {
int uframe_num = dwc2_readl(dwc2, HFNUM);
 
if (!(uframe_num & 0x1))
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 1/7] usb: dwc2: Add host controller driver

2020-01-22 Thread Jules Maselbas
The host driver is taken from U-Boot and mix with some part from Linux.

Signed-off-by: Jules Maselbas 
---
 drivers/usb/Kconfig   |   2 +
 drivers/usb/Makefile  |   1 +
 drivers/usb/dwc2/Kconfig  |   4 +
 drivers/usb/dwc2/Makefile |   1 +
 drivers/usb/dwc2/core.c   | 614 +++
 drivers/usb/dwc2/core.h   | 546 
 drivers/usb/dwc2/dwc2.c   | 101 +
 drivers/usb/dwc2/dwc2.h   |  41 ++
 drivers/usb/dwc2/host.c   | 617 +++
 drivers/usb/dwc2/regs.h   | 847 ++
 drivers/usb/dwc2/rhub.c   | 419 +++
 11 files changed, 3193 insertions(+)
 create mode 100644 drivers/usb/dwc2/Kconfig
 create mode 100644 drivers/usb/dwc2/Makefile
 create mode 100644 drivers/usb/dwc2/core.c
 create mode 100644 drivers/usb/dwc2/core.h
 create mode 100644 drivers/usb/dwc2/dwc2.c
 create mode 100644 drivers/usb/dwc2/dwc2.h
 create mode 100644 drivers/usb/dwc2/host.c
 create mode 100644 drivers/usb/dwc2/regs.h
 create mode 100644 drivers/usb/dwc2/rhub.c

diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 99eff1c8d..aab1564ab 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -9,6 +9,8 @@ if USB_HOST
 
 source "drivers/usb/imx/Kconfig"
 
+source "drivers/usb/dwc2/Kconfig"
+
 source "drivers/usb/dwc3/Kconfig"
 
 source "drivers/usb/host/Kconfig"
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 9e9809950..ecd7ad1d3 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_USB)  += core/
 obj-$(CONFIG_USB_IMX_CHIPIDEA) += imx/
+obj-$(CONFIG_USB_DWC2) += dwc2/
 obj-$(CONFIG_USB_DWC3) += dwc3/
 obj-$(CONFIG_USB_MUSB) += musb/
 obj-$(CONFIG_USB_GADGET)   += gadget/
diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig
new file mode 100644
index 0..c88134cbb
--- /dev/null
+++ b/drivers/usb/dwc2/Kconfig
@@ -0,0 +1,4 @@
+config USB_DWC2
+   bool "DWC2 driver"
+   help
+ DesignWare Core USB2 OTG driver.
diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile
new file mode 100644
index 0..3b922c282
--- /dev/null
+++ b/drivers/usb/dwc2/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_USB_DWC2) += dwc2.o core.o host.o rhub.o
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
new file mode 100644
index 0..0046e955f
--- /dev/null
+++ b/drivers/usb/dwc2/core.c
@@ -0,0 +1,614 @@
+// SPDX-License-Identifier: GPL-2.0+
+#include "dwc2.h"
+
+void dwc2_set_param_otg_cap(struct dwc2 *dwc2)
+{
+   u8 val;
+
+   switch (dwc2->hw_params.op_mode) {
+   case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
+   val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
+   break;
+   case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
+   case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
+   case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
+   val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
+   break;
+   default:
+   val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
+   break;
+   }
+
+   dwc2->params.otg_cap = val;
+}
+
+void dwc2_set_param_phy_type(struct dwc2 *dwc2)
+{
+   u8 val;
+
+   switch (dwc2->hw_params.hs_phy_type) {
+   case GHWCFG2_HS_PHY_TYPE_UTMI:
+   case GHWCFG2_HS_PHY_TYPE_UTMI_ULPI:
+   val = DWC2_PHY_TYPE_PARAM_UTMI;
+   break;
+   case GHWCFG2_HS_PHY_TYPE_ULPI:
+   val = DWC2_PHY_TYPE_PARAM_ULPI;
+   break;
+   case GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED:
+   val = DWC2_PHY_TYPE_PARAM_FS;
+   break;
+   }
+
+   dwc2->params.phy_type = val;
+}
+
+void dwc2_set_param_speed(struct dwc2 *dwc2)
+{
+   if (dwc2->params.phy_type == DWC2_PHY_TYPE_PARAM_FS)
+   dwc2->params.speed = DWC2_SPEED_PARAM_FULL;
+   else
+   dwc2->params.speed = DWC2_SPEED_PARAM_HIGH;
+}
+
+void dwc2_set_param_phy_utmi_width(struct dwc2 *dwc2)
+{
+   int val;
+
+   val = (dwc2->hw_params.utmi_phy_data_width ==
+  GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
+
+   dwc2->params.phy_utmi_width = val;
+}
+
+/**
+ * dwc2_set_default_params() - Set all core parameters to their
+ * auto-detected default values.
+ *
+ * @dwc2: Programming view of the DWC2 controller
+ *
+ */
+void dwc2_set_default_params(struct dwc2 *dwc2)
+{
+   struct dwc2_hw_params *hw = >hw_params;
+   struct dwc2_core_params *p = >params;
+   bool dma_capable = !(hw->arch == GHWCFG2_SLAVE_ONLY_ARCH);
+
+   dwc2_set_param_otg_cap(dwc2);
+   dwc2_set_param_phy_type(dwc2);
+   dwc2_set_param_speed(dwc2);
+   dwc2_set_param_phy_utmi_width(dwc2);
+   p->phy_ulpi_ddr = false;
+   p->phy_ulpi_ext_vbus = false;
+
+   p->enable_dynamic_fifo = hw->enable_dynamic_fifo;
+   p->en_multiple_tx_fifo = hw->en_multiple_tx_fifo;
+   p->i2c_enable = hw->i2c_enable;
+   p->acg_enable = hw->acg_enable;
+   

[RFC PATCH 1/9] BACKPORT: usb: Add helper to extract bits 12:11 of wMaxPacketize

2020-01-22 Thread Jules Maselbas
According to USB Specification 2.0 table 9-4,
wMaxPacketSize is a bitfield. Endpoint's maxpacket
is laid out in bits 10:0. For high-speed,
high-bandwidth isochronous endpoints, bits 12:11
contain a multiplier to tell us how many
transactions we want to try per uframe.

This means that if we want an isochronous endpoint
to issue 3 transfers of 1024 bytes per uframe,
wMaxPacketSize should contain the value:

1024 | (2 << 11)

or 5120 (0x1400). In order to make Host and
Peripheral controller drivers' life easier, we're
adding a helper which returns bits 12:11. Note that
no care is made WRT to checking endpoint type and
gadget's speed. That's left for drivers to handle.

(cherry picked from linux commit 541b6fe63023f3059cf85d47ff2767a3e42a8e44)

Signed-off-by: Jules Maselbas 
---
 include/usb/ch9.h | 20 
 1 file changed, 20 insertions(+)

diff --git a/include/usb/ch9.h b/include/usb/ch9.h
index 85f3e64ca..fc6ec862c 100644
--- a/include/usb/ch9.h
+++ b/include/usb/ch9.h
@@ -1,3 +1,4 @@
+
 /*
  * This file holds USB constants and structures that are needed for
  * USB device APIs.  These are used by the USB device model, which is
@@ -400,6 +401,11 @@ struct usb_endpoint_descriptor {
 #define USB_ENDPOINT_XFER_INT  3
 #define USB_ENDPOINT_MAX_ADJUSTABLE0x80
 
+#define USB_EP_MAXP_MULT_SHIFT 11
+#define USB_EP_MAXP_MULT_MASK  (3 << USB_EP_MAXP_MULT_SHIFT)
+#define USB_EP_MAXP_MULT(m) \
+   (((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT)
+
 /* The USB 3.0 spec redefines bits 5:4 of bmAttributes as interrupt ep type. */
 #define USB_ENDPOINT_INTRTYPE  0x30
 #define USB_ENDPOINT_INTR_PERIODIC (0 << 4)
@@ -596,6 +602,20 @@ static inline int usb_endpoint_is_isoc_out(
return usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd);
 }
 
+/**
+ * usb_endpoint_maxp_mult - get endpoint's transactional opportunities
+ * @epd: endpoint to be checked
+ *
+ * Return @epd's wMaxPacketSize[12:11] + 1
+ */
+static inline int
+usb_endpoint_maxp_mult(const struct usb_endpoint_descriptor *epd)
+{
+   int maxp = __le16_to_cpu(epd->wMaxPacketSize);
+
+   return USB_EP_MAXP_MULT(maxp) + 1;
+}
+
 /**
  * usb_endpoint_maxp - get endpoint's max packet size
  * @epd: endpoint to be checked
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 5/7] usb: dwc2: host: Dynamic fifo size support from Linux

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/host.c | 146 ++--
 drivers/usb/dwc2/regs.h |   8 ---
 2 files changed, 124 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
index 09cf04b46..5be101752 100644
--- a/drivers/usb/dwc2/host.c
+++ b/drivers/usb/dwc2/host.c
@@ -436,6 +436,129 @@ int dwc2_submit_int_msg(struct usb_device *udev, unsigned 
long pipe,
}
 }
 
+/*
+ * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size
+ * For system that have a total fifo depth that is smaller than the default
+ * RX + TX fifo size.
+ *
+ * @dwc2: Programming view of DWC_otg controller
+ */
+static void dwc2_calculate_dynamic_fifo(struct dwc2 *dwc2)
+{
+   struct dwc2_core_params *params = >params;
+   struct dwc2_hw_params *hw = >hw_params;
+   u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size;
+
+   total_fifo_size = hw->total_fifo_size;
+   rxfsiz = params->host_rx_fifo_size;
+   nptxfsiz = params->host_nperio_tx_fifo_size;
+   ptxfsiz = params->host_perio_tx_fifo_size;
+
+   /*
+* Will use Method 2 defined in the DWC2 spec: minimum FIFO depth
+* allocation with support for high bandwidth endpoints. Synopsys
+* defines MPS(Max Packet size) for a periodic EP=1024, and for
+* non-periodic as 512.
+*/
+   if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)) {
+   /*
+* For Buffer DMA mode/Scatter Gather DMA mode
+* 2 * ((Largest Packet size / 4) + 1 + 1) + n
+* with n = number of host channel.
+* 2 * ((1024/4) + 2) = 516
+*/
+   rxfsiz = 516 + hw->host_channels;
+
+   /*
+* min non-periodic tx fifo depth
+* 2 * (largest non-periodic USB packet used / 4)
+* 2 * (512/4) = 256
+*/
+   nptxfsiz = 256;
+
+   /*
+* min periodic tx fifo depth
+* (largest packet size*MC)/4
+* (1024 * 3)/4 = 768
+*/
+   ptxfsiz = 768;
+   }
+
+   params->host_rx_fifo_size = rxfsiz;
+   params->host_nperio_tx_fifo_size = nptxfsiz;
+   params->host_perio_tx_fifo_size = ptxfsiz;
+
+   /*
+* If the summation of RX, NPTX and PTX fifo sizes is still
+* bigger than the total_fifo_size, then we have a problem.
+*
+* We won't be able to allocate as many endpoints. Right now,
+* we're just printing an error message, but ideally this FIFO
+* allocation algorithm would be improved in the future.
+*
+* FIXME improve this FIFO allocation algorithm.
+*/
+   if (unlikely(total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)))
+   dwc2_err(dwc2, "invalid fifo sizes\n");
+}
+
+static void dwc2_config_fifos(struct dwc2 *dwc2)
+{
+   struct dwc2_core_params *params = >params;
+   u32 nptxfsiz, hptxfsiz, dfifocfg, grxfsiz;
+
+   if (!params->enable_dynamic_fifo)
+   return;
+
+   dwc2_calculate_dynamic_fifo(dwc2);
+
+   /* Rx FIFO */
+   grxfsiz = dwc2_readl(dwc2, GRXFSIZ);
+   dwc2_dbg(dwc2, "initial grxfsiz=%08x\n", grxfsiz);
+   grxfsiz &= ~GRXFSIZ_DEPTH_MASK;
+   grxfsiz |= params->host_rx_fifo_size <<
+  GRXFSIZ_DEPTH_SHIFT & GRXFSIZ_DEPTH_MASK;
+   dwc2_writel(dwc2, grxfsiz, GRXFSIZ);
+   dwc2_dbg(dwc2, "new grxfsiz=%08x\n", dwc2_readl(dwc2, GRXFSIZ));
+
+   /* Non-periodic Tx FIFO */
+   dwc2_dbg(dwc2, "initial gnptxfsiz=%08x\n", dwc2_readl(dwc2, GNPTXFSIZ));
+   nptxfsiz = params->host_nperio_tx_fifo_size <<
+  FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
+   nptxfsiz |= params->host_rx_fifo_size <<
+   FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
+   dwc2_writel(dwc2, nptxfsiz, GNPTXFSIZ);
+   dwc2_dbg(dwc2, "new gnptxfsiz=%08x\n", dwc2_readl(dwc2, GNPTXFSIZ));
+
+   /* Periodic Tx FIFO */
+   dwc2_dbg(dwc2, "initial hptxfsiz=%08x\n", dwc2_readl(dwc2, HPTXFSIZ));
+   hptxfsiz = params->host_perio_tx_fifo_size <<
+  FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
+   hptxfsiz |= (params->host_rx_fifo_size +
+params->host_nperio_tx_fifo_size) <<
+   FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
+   dwc2_writel(dwc2, hptxfsiz, HPTXFSIZ);
+   dwc2_dbg(dwc2, "new hptxfsiz=%08x\n", dwc2_readl(dwc2, HPTXFSIZ));
+
+   if (dwc2->params.en_multiple_tx_fifo &&
+   dwc2->hw_params.snpsid >= DWC2_CORE_REV_2_91a) {
+   /*
+* This feature was implemented in 2.91a version
+* Global DFIFOCFG calculation for Host mode -
+* include RxFIFO, NPTXFIFO and HPTXFIFO
+*/
+   dfifocfg = dwc2_readl(dwc2, GDFIFOCFG);
+

[PATCH v2 0/7] usb: dwc2 host driver

2020-01-22 Thread Jules Maselbas
Hi,

This patchset add USB host support for the DWC2 controller
As I said before, this driver comes from U-Boot and is modified
with some part taken from Linux.

I've only tested this driver on our custom SoC (k1c MPPA Coolidge)
using an external ULPI phy.  More tests are welcome.

changes since rfc:
 - error message for timeout in wait bit set/clear
 - in the commit 'Fix toggle reset': pipe is used instead of
   wIndex field from setup packet to get epnum and in.

---

Jules Maselbas (7):
  usb: dwc2: Add host controller driver
  usb: dwc2: host: Read dr_mode from device tree
  usb: dwc2: host: Rework roothub interface
  usb: dwc2: host: Handle dma mapping errors
  usb: dwc2: host: Dynamic fifo size support from Linux
  usb: dwc2: host: Fix toggle reset
  usb: dwc2: host: Rewrite dwc2_hc_init

 drivers/usb/Kconfig   |   2 +
 drivers/usb/Makefile  |   1 +
 drivers/usb/dwc2/Kconfig  |   4 +
 drivers/usb/dwc2/Makefile |   1 +
 drivers/usb/dwc2/core.c   | 703 
 drivers/usb/dwc2/core.h   | 546 +
 drivers/usb/dwc2/dwc2.c   | 103 +
 drivers/usb/dwc2/dwc2.h   |  42 ++
 drivers/usb/dwc2/host.c   | 747 +
 drivers/usb/dwc2/regs.h   | 839 ++
 drivers/usb/dwc2/rhub.c   | 384 +
 11 files changed, 3372 insertions(+)
 create mode 100644 drivers/usb/dwc2/Kconfig
 create mode 100644 drivers/usb/dwc2/Makefile
 create mode 100644 drivers/usb/dwc2/core.c
 create mode 100644 drivers/usb/dwc2/core.h
 create mode 100644 drivers/usb/dwc2/dwc2.c
 create mode 100644 drivers/usb/dwc2/dwc2.h
 create mode 100644 drivers/usb/dwc2/host.c
 create mode 100644 drivers/usb/dwc2/regs.h
 create mode 100644 drivers/usb/dwc2/rhub.c

-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 2/7] usb: dwc2: host: Read dr_mode from device tree

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/core.c | 89 +
 drivers/usb/dwc2/dwc2.c |  2 +
 drivers/usb/dwc2/dwc2.h |  1 +
 3 files changed, 92 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 0046e955f..1812de034 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -1,6 +1,33 @@
 // SPDX-License-Identifier: GPL-2.0+
 #include "dwc2.h"
 
+/* Returns the controller's GHWCFG2.OTG_MODE. */
+static unsigned int dwc2_op_mode(struct dwc2 *dwc2)
+{
+   u32 ghwcfg2 = dwc2_readl(dwc2, GHWCFG2);
+
+   return (ghwcfg2 & GHWCFG2_OP_MODE_MASK) >>
+   GHWCFG2_OP_MODE_SHIFT;
+}
+
+/* Returns true if the controller is host-only. */
+static bool dwc2_hw_is_host(struct dwc2 *dwc2)
+{
+   unsigned int op_mode = dwc2_op_mode(dwc2);
+
+   return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_HOST) ||
+   (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST);
+}
+
+/* Returns true if the controller is device-only. */
+static bool dwc2_hw_is_device(struct dwc2 *dwc2)
+{
+   unsigned int op_mode = dwc2_op_mode(dwc2);
+
+   return (op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
+   (op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE);
+}
+
 void dwc2_set_param_otg_cap(struct dwc2 *dwc2)
 {
u8 val;
@@ -493,6 +520,68 @@ void dwc2_gusbcfg_init(struct dwc2 *dwc2)
dwc2_writel(dwc2, usbcfg, GUSBCFG);
 }
 
+/*
+ * Check the dr_mode against the module configuration and hardware
+ * capabilities.
+ *
+ * The hardware, module, and dr_mode, can each be set to host, device,
+ * or otg. Check that all these values are compatible and adjust the
+ * value of dr_mode if possible.
+ *
+ *  actual
+ *HW  MOD dr_mode   dr_mode
+ *  --
+ *   HST  HST  any:  HST
+ *   HST  DEV  any:  ---
+ *   HST  OTG  any:  HST
+ *
+ *   DEV  HST  any:  ---
+ *   DEV  DEV  any:  DEV
+ *   DEV  OTG  any:  DEV
+ *
+ *   OTG  HST  any:  HST
+ *   OTG  DEV  any:  DEV
+ *   OTG  OTG  any:  dr_mode
+ */
+int dwc2_get_dr_mode(struct dwc2 *dwc2)
+{
+   enum usb_dr_mode mode;
+
+   mode = of_usb_get_dr_mode(dwc2->dev->device_node, NULL);
+   dwc2->dr_mode = mode;
+
+   if (dwc2_hw_is_device(dwc2)) {
+   if (IS_ENABLED(CONFIG_USB_DWC2_HOST)) {
+   dwc2_err(dwc2,
+   "Controller does not support host mode.\n");
+   return -EINVAL;
+   }
+   mode = USB_DR_MODE_PERIPHERAL;
+   } else if (dwc2_hw_is_host(dwc2)) {
+   if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL)) {
+   dwc2_err(dwc2,
+   "Controller does not support device mode.\n");
+   return -EINVAL;
+   }
+   mode = USB_DR_MODE_HOST;
+   } else {
+   if (IS_ENABLED(CONFIG_USB_DWC2_HOST))
+   mode = USB_DR_MODE_HOST;
+   else if (IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL))
+   mode = USB_DR_MODE_PERIPHERAL;
+   }
+
+   if (mode != dwc2->dr_mode) {
+   dwc2_warn(dwc2,
+"Configuration mismatch. dr_mode forced to %s\n",
+   mode == USB_DR_MODE_HOST ? "host" : "device");
+
+   dwc2->dr_mode = mode;
+   }
+
+   return 0;
+}
+
 /*
  * Do core a soft reset of the core.  Be careful with this because it
  * resets all the internal state machines of the core.
diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
index 893f573bc..1df393e77 100644
--- a/drivers/usb/dwc2/dwc2.c
+++ b/drivers/usb/dwc2/dwc2.c
@@ -62,6 +62,8 @@ static int dwc2_probe(struct device_d *dev)
/* Detect config values from hardware */
dwc2_get_hwparams(dwc2);
 
+   dwc2_get_dr_mode(dwc2);
+
dwc2_set_default_params(dwc2);
 
dma_set_mask(dev, DMA_BIT_MASK(32));
diff --git a/drivers/usb/dwc2/dwc2.h b/drivers/usb/dwc2/dwc2.h
index 0ac4b40fc..60cdca520 100644
--- a/drivers/usb/dwc2/dwc2.h
+++ b/drivers/usb/dwc2/dwc2.h
@@ -21,6 +21,7 @@ void dwc2_flush_all_fifo(struct dwc2 *dwc2);
 int dwc2_phy_init(struct dwc2 *dwc2, bool select_phy);
 int dwc2_gahbcfg_init(struct dwc2 *dwc2);
 void dwc2_gusbcfg_init(struct dwc2 *dwc2);
+int dwc2_get_dr_mode(struct dwc2 *dwc2);
 
 int dwc2_core_reset(struct dwc2 *dwc2);
 void dwc2_core_init(struct dwc2 *dwc2);
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 6/7] usb: dwc2: host: Fix toggle reset

2020-01-22 Thread Jules Maselbas
>From USB 2.0 specification, section 9.4.5:
  ClearFeature(ENDPOINT_HALT) request always results in
  the data toggle being reinitialized to DATA0.

The hacky solution for now is to reset the toggle bit to DATA0 when
the host controller send a ClearFeature request on an endpoint.

Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/host.c | 16 
 1 file changed, 16 insertions(+)

diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
index 5be101752..e6344ea41 100644
--- a/drivers/usb/dwc2/host.c
+++ b/drivers/usb/dwc2/host.c
@@ -372,7 +372,23 @@ int dwc2_submit_control_msg(struct usb_device *udev,
if (ret)
return ret;
 
+   if (setup->requesttype == USB_RECIP_ENDPOINT
+   && setup->request == USB_REQ_CLEAR_FEATURE) {
+   /* From USB 2.0, section 9.4.5:
+* ClearFeature(ENDPOINT_HALT) request always results
+* in the data toggle being reinitialized to DATA0.
+*/
+   int ep = usb_pipeendpoint(pipe);
+   int data0 = TSIZ_SC_MC_PID_DATA0;
+
+   if (usb_pipein(pipe))
+   dwc2->in_data_toggle[devnum][ep] = data0;
+   else
+   dwc2->out_data_toggle[devnum][ep] = data0;
+   }
+
udev->act_len = act_len;
+   udev->status = 0;
 
return 0;
 }
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 4/7] usb: dwc2: host: Handle dma mapping errors

2020-01-22 Thread Jules Maselbas
Signed-off-by: Jules Maselbas 
---
 drivers/usb/dwc2/host.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/dwc2/host.c b/drivers/usb/dwc2/host.c
index 61c29910e..09cf04b46 100644
--- a/drivers/usb/dwc2/host.c
+++ b/drivers/usb/dwc2/host.c
@@ -153,6 +153,11 @@ static int transfer_chunk(struct dwc2 *dwc2, u8 hc,
dma_addr = dma_map_single(dwc2->dev, buffer, xfer_len,
  in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
 
+   if (dma_mapping_error(dwc2->dev, dma_addr)) {
+   dwc2_err(dwc2, "Failed to map buffer@0x%p for dma\n", buffer);
+   return -EFAULT;
+   }
+
dwc2_dbg(dwc2, "chunk: pid=%d xfer_len=%u pkts=%u dma_addr=%llx\n",
*pid, xfer_len, num_packets, dma_addr);
 
-- 
2.21.0.196.g041f5ea


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/3] watchdog: Select CONFIG_PARAMETER

2020-01-22 Thread Christian Eggers
Hi Sascha,

Am Mittwoch, 22. Januar 2020, 09:21:15 CET schrieb Sascha Hauer:
> Hi Christian,
> 
> > diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> > index 45dd41a2a..34b7fea39 100644
> > --- a/drivers/watchdog/Kconfig
> > +++ b/drivers/watchdog/Kconfig
> > @@ -4,6 +4,7 @@ config WATCHDOG_IMX_RESET_SOURCE
> > 
> >  menuconfig WATCHDOG
> >  
> > bool "Watchdog support"
> > 
> > +   select PARAMETER
> 
> I think this goes into the wrong direction. With CONFIG_PARAMETER
> enabled we get support for adjusting device parameters from the shell.
> In environments without shell support parameter support is not needed.
> For example the watchdog C API doesn't need parameter support and is
> still usable.
> 
> The static inline wrappers for dev_add_param_* should return NULL
> instead of returning ERR_PTR(-ENOSYS).

initially I came to the same result. But previous commits to param.h went in 
the opposite direction:

> 03b59bdb64 ("paramter: The dev_add_param_*() return ERR_PTR(), change
> no-ops") to return ERR_PTR(-ENOSYS) instead of NULL
> 
> Signed-off-by: Marc Kleine-Budde 
> Signed-off-by: Sascha Hauer 

and

> c5d95eb4c7 ("param: make parameter functions more consistent")
>
> Signed-off-by: Sascha Hauer 

Most of the callers of dev_add_param*()  don't care about the returned param 
pointer at all. Some are checking against PTR_ERR() which would not be hit if 
returning NULL (this is what we want).

A few callers have to changed if a NULL pointer can be returned:
- __nvvar_add()
- state_string_create()  stores the result in state_string::param, but seems 
to be used nowhere
- mci_register() dito for mci::param_probe
- state_uint8_create() dito for state_uint32::param
- state_uint32_create() dito

For me it looks reasonable to return a NULL pointer if CONFIG_PARAMETER is not 
set (as you suggested). Only __nvvar_add() needs slight changes and I would 
remove needless storage of param in structs state_string, mci and 
state_uint32.

Shall I start?

regards
Christian



___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH v3 2/3] imd: add support for checksum generation/verification

2020-01-22 Thread Sascha Hauer
On Mon, Jan 20, 2020 at 03:58:20PM +0100, Steffen Trumtrar wrote:
> Add a new imd type "checksum". This type consists of the CRC32 checksum
> of the whole barebox image minus the checksum itself.
> The checksum can be written to the imd field with the bareboximd host-tool.
> It can be verified with said tool or with "imd" on the target.
> 
> Signed-off-by: Steffen Trumtrar 
> ---
> Changes in v3:
>   - moved the flags field to the uint32_t tag
> 
>  commands/imd.c   |   1 +
>  common/imd-barebox.c |   1 +
>  common/imd.c | 169 ++-
>  include/image-metadata.h |  42 ++
>  scripts/bareboximd.c |  32 
>  5 files changed, 244 insertions(+), 1 deletion(-)
> 
> diff --git a/commands/imd.c b/commands/imd.c
> index f1a22cef96bd..16ab7290c920 100644
> --- a/commands/imd.c
> +++ b/commands/imd.c
> @@ -46,6 +46,7 @@ BAREBOX_CMD_HELP_TEXT("Options:")
>  BAREBOX_CMD_HELP_OPT ("-t ", "only show information of ")
>  BAREBOX_CMD_HELP_OPT ("-n ", "for tags with multiple strings only show 
> string ")
>  BAREBOX_CMD_HELP_OPT ("-s VARNAME",  "set variable VARNAME instead of 
> showing information")
> +BAREBOX_CMD_HELP_OPT ("-V",  "Verify checksum of image")
>  BAREBOX_CMD_HELP_TEXT("")
>  BAREBOX_CMD_HELP_TEXT("Without options all information available is printed. 
> Valid types are:")
>  BAREBOX_CMD_HELP_TEXT("release, build, model, of_compatible")
> diff --git a/common/imd-barebox.c b/common/imd-barebox.c
> index e9cd37d83ec8..4aec51bfbdc2 100644
> --- a/common/imd-barebox.c
> +++ b/common/imd-barebox.c
> @@ -23,3 +23,4 @@ __BAREBOX_IMD_SECTION(.barebox_imd_end) = {
>  
>  BAREBOX_IMD_TAG_STRING(imd_build_tag, IMD_TYPE_BUILD, UTS_VERSION, 1);
>  BAREBOX_IMD_TAG_STRING(imd_release_tag, IMD_TYPE_RELEASE, UTS_RELEASE, 1);
> +BAREBOX_IMD_CRC(imd_checksum, 0x0, 1);
> diff --git a/common/imd.c b/common/imd.c
> index e0dab69644c0..b8429184777b 100644
> --- a/common/imd.c
> +++ b/common/imd.c
> @@ -22,6 +22,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #ifndef CONFIG_CMD_IMD
>  int imd_command_setenv(const char *variable_name, const char *value)
> @@ -167,6 +168,9 @@ static struct imd_type_names imd_types[] = {
>   }, {
>   .type = IMD_TYPE_OF_COMPATIBLE,
>   .name = "of_compatible",
> + }, {
> + .type = IMD_TYPE_CHECKSUM,
> + .name = "checksum",

Given that it's specifically a CRC32 sum it should be named like this.
In the end a sh256sum is also a checksum, so we shouldn't pollute the
namespace like this.

> @@ -299,10 +449,12 @@ int imd_command(int argc, char *argv[])
>   const char *filename;
>   const char *variable_name = NULL;
>   char *str;
> + uint32_t checksum = 0;
> + uint32_t verify = 0;
>  
>   imd_command_verbose = 0;
>  
> - while ((opt = getopt(argc, argv, "vt:s:n:")) > 0) {
> + while ((opt = getopt(argc, argv, "vt:s:n:cV")) > 0) {
>   switch(opt) {
>   case 't':
>   type = imd_name_to_type(optarg);
> @@ -320,6 +472,12 @@ int imd_command(int argc, char *argv[])
>   case 'n':
>   strno = simple_strtoul(optarg, NULL, 0);
>   break;
> + case 'c':
> + checksum = 1;
> + break;
> + case 'V':
> + verify = 1;
> + break;

These new options are not documented in commands/imd.c.

The Linux imd command should have a help function as well, but that's a
different topic.

> diff --git a/include/image-metadata.h b/include/image-metadata.h
> index 5904d95acd37..637a611a39a1 100644
> --- a/include/image-metadata.h
> +++ b/include/image-metadata.h
> @@ -25,9 +25,12 @@
>  #define IMD_TYPE_MODEL   0x640c8004 /* The board name this image 
> is for */
>  #define IMD_TYPE_OF_COMPATIBLE   0x640c8005 /* the device tree 
> compatible string */
>  #define IMD_TYPE_PARAMETER   0x640c8006 /* A generic parameter. Use 
> key=value as data */
> +#define IMD_TYPE_CHECKSUM0x640c1007 /* the checksum of the barebox 
> images */
>  #define IMD_TYPE_END 0x640c7fff
>  #define IMD_TYPE_INVALID 0x
>  
> +#define IMD_FLAG_TAG_VALID   (1 << 0)

This should be specific to a crc32 tag.

> +
>  /*
>   * The IMD header. All data is stored in little endian format in the image.
>   * The next header starts at the next 4 byte boundary after the data.
> @@ -51,6 +54,25 @@ static inline int imd_is_string(uint32_t type)
>   return (type & 0x8000) ? 1 : 0;
>  }
>  
> +static inline int imd_is_uint32(uint32_t type)
> +{
> + return (type & 0x1000) ? 1 : 0;
> +}

Erm, no. Please don't reserve bits in the IMD_TYPE_ defines without
documenting it anywhere.

> +
> +static inline int imd_entry_is_valid(uint32_t flags)
> +{
> + return (flags & IMD_FLAG_TAG_VALID) ? 1 : 0;
> +}
> +
> +/*
> + * A IMD int.
> + */
> +struct imd_entry_uint32 {
> + 

Re: [PATCH] watchdog: Fix error path

2020-01-22 Thread Sascha Hauer
On Tue, Jan 21, 2020 at 12:02:41PM +0100, Christian Eggers wrote:
> In case of an error (e.g. dev_add_param_tristate_ro() returns -ENOSYS),
> device registration must be reverted.
> 
> Signed-off-by: Christian Eggers 
> ---
>  drivers/watchdog/wd_core.c | 30 +-
>  1 file changed, 21 insertions(+), 9 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 1/3] watchdog: Select CONFIG_PARAMETER

2020-01-22 Thread Sascha Hauer
Hi Christian,

On Tue, Jan 21, 2020 at 12:44:19PM +0100, Christian Eggers wrote:
> Without CONFIG_PARAMETER, watchdog_register() will always fail.
> 
> Signed-off-by: Christian Eggers 
> ---
>  drivers/watchdog/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
> index 45dd41a2a..34b7fea39 100644
> --- a/drivers/watchdog/Kconfig
> +++ b/drivers/watchdog/Kconfig
> @@ -4,6 +4,7 @@ config WATCHDOG_IMX_RESET_SOURCE
>  
>  menuconfig WATCHDOG
>   bool "Watchdog support"
> + select PARAMETER

I think this goes into the wrong direction. With CONFIG_PARAMETER
enabled we get support for adjusting device parameters from the shell.
In environments without shell support parameter support is not needed.
For example the watchdog C API doesn't need parameter support and is
still usable.

The static inline wrappers for dev_add_param_* should return NULL
instead of returning ERR_PTR(-ENOSYS).

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] param: Make enum param_tristate always visible

2020-01-22 Thread Sascha Hauer
On Tue, Jan 21, 2020 at 11:45:27AM +0100, Christian Eggers wrote:
> When disabling CONFIG_SHELL_HUSH, also CONFIG_PARAMETER may be disabled.
> In this case, the definition "enum param_tristate" is not reachable from
> watchdog.h.
> 
> I also considered moving almost everything in watchdog.h inside the
> CONFIG_WATCHDOG guard. But this doesn't work for me because
> drivers/watchdog/imxwd.c can also be built without CONFIG_WATCHDOG.
> 
> Signed-off-by: Christian Eggers 
> ---

Applied, thanks.

>  @Sascha: I've asked my IT department to stop modifiying my patch
> emails. I hope the mails are ok now.

Yes, this works now, thanks ;)

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox