USB: ci13xxx_udc.c: remove err() usage

err() was a very old USB-specific macro that I thought had
gone away.  This patch removes it from being used in the
driver and uses dev_err() instead.

CC: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: use module_pci_driver

This patch converts the drivers in drivers/usb/gadget/* to use
module_pci_driver() macro which makes the code smaller and a bit simpler.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Cc: Thomas Dahlmann <dahlmann.thomas@arcor.de>
Cc: Xiaochen Shen <xiaochen.shen@intel.com>
Cc: Pavankumar Kondeti <pkondeti@codeaurora.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
usb: gadget: Update ci13xxx_udc to use usb_endpoint_descriptor inside the struct usb_ep

Remove redundant pointer to struct usb_endpoint_descriptor.

Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
usb: gadget: Update langwell_udc to use usb_endpoint_descriptor inside the struct usb_ep

Remove redundant pointer to struct usb_endpoint_descriptor.

Signed-off-by: Ido Shayevitz <idos@codeaurora.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>
USB: gadget: ci13xx_udc: remove unused err() macro

I previously cleaned up the err() call usage in this driver, but it
really was calling this macro instead.  To remove future confusion, just
delete this unused macro now.

Ideally, the warn() and info() macros should also be removed, and the
"real" dev_warn() and dev_info() calls should be used instead.

Reported-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: fix ep list removal in gadget unregistering code

Since ep0{out,in} are never on gadget's ep_list, there's no need to try
to unlink them, even more so because ep_list linkage is not initialized
for these endpoints.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: initialize ep0{out,in} dynamically

Change ep0{out,in} macros into dynamically assigned pointers in
gadget initialization time.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: rename register layouts

Currently, the register prefixes in the driver seem to be mixed: the
capability registers are the ones that contain capability information,
such as number of hardware endpoints, while the registers that are
used to program the controller are called operational registers.

Normally, capability registers start at 0x100 offset of the register
window and are followed by operational registers. In some versions,
however, capability registers start at 0x0 offset.

This patch renames the register and adjusts their offsets appropriately,
leaving the possibility of having a non-standard capability offset.

I couldn't find any mentions of the TESTMODE register anywhere, so I
suspect it might only be enabled in chipidea internal versions of the
controller and I'm really inclined to remove it from the driver or at
least hiding it behind a config option.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx_pci: add langwell/penwell pci ids

Add pci ids for ChipIdea UDC as found in langwell/penwell SoCs.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: drop needless parens

Small and self-evident cleanup.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: move global variables inside struct ci13xxx

Make global variables that are specific for each UDC instance part of
struct ci13xxx.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: redo register access

Use lookup table instead of conditional macrodefinitions of register
addresses. With two different possible register layouts and different
register offsets, it's easiest to build a table with register addresses
at probe time, based on the information supplied from the platform and
device capabilities. This way we get rid of branch-per-register-access.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: convert to platform device

Let's break ci13xxx driver into a separate udc driver and platform
drivers _pci and _msm, which will create a platform device for each pci
(or msm) device found. The approach was introduced by Felipe in dwc3
driver and there seems to be no reason not to use it.

msm related code is only compile-tested.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: replace home-brewed logging with dev_{err,warn,info}

Logging output in the driver is mostly done using custom err/warn/info
macros which rely on the existence of the global variable _udc, which
is a global reference to the udc controller structure. This reference
will have to go in order to allow us to have more than one chipidea udc
in the system.

Thus, replace custom macros with dev_{err,warn,info} using the platform
device where possible. The trace() macro, which is a nop by default is
left for tracing purposes.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: move endpoint (de-)initialization to probe/remove

Currently, endpoints are initialized in gadget start/stop methods, however
for the new style gadgets it is expected that bind() can be called before
controller's start(), and we need endpoints already initialized at that
point. So, move endpoint initialization to controller's probe before we
switch to the "new style" gadget framework.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: convert to new style

Finally, convert to the new style framework, using udc_start/udc_stop
methods. Since there is no need in the global _udc pointer, remove it.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
USB: gadget: ci13xx_udc: fix potential crash in irq handler

As pointed out by Dan Carpenter, we should not be trying to call
dev_err() on a structure that was previously determined to be NULL,
that's just foolish and asking for trouble.

So just delete the message, it's not going to do anyone any good to have
it anyway.

This problem was caused by 0f089094cde5: "usb: gadget: ci13xxx: replace
home-brewed logging with dev_{err,warn,info}"

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
USB: gadget: ci13xx_pci: remove unneeded check in ci13xxx_pci_probe()

As pointed out by Dan Carpenter, the check for NULL for the id variable
is no longer needed, especially as we just dereferenced it a few lines
earlier, causing an oops if it really was NULL.

This was caused by 62bb84ed0e4d: "usb: gadget: ci13xxx: convert to
platform device".

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx_pci: guard against devices without driver_data

Don't try to initialize devices that don't have driver_data assigned
to their pci ids.

Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
usb: gadget: ci13xxx: get rid of local tracing for good

There is no point in having tracing output in the kernel these days.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>