sunxi-usb: Fix stack corruption in sw_hcd0.c

Enlarge aInfo array to fit all text added to it.
Fixes stack corruption, and solves ERR: request_irq 38 failed! error.
sunxi_usb-sw_hcd0: Fix overwriting struct sw_hcd memory

When running the latest sunxi-3.0 on my gooseberry, sw_hcd0 would fail
to init and on plugging in a otg-host cable to enable, because of request_irq
failing. The reason for this failure is that sw_hcd->isr was set to NULL,
as it had been overwritten from ep_config_from_table().

The sw_hcd endpoints array has SW_HCD_C_NUM_EPS entries, and before this
patch that equaled USBC_MAX_EP_NUM. But USBC_MAX_EP_NUM gives the maximum
ep address, and per ep address we've 2 sw_hcd.endpoints entries!

This patch both adds a check for not going out of bounds wrt sw_hcd.endpoints
to ep_config_from_table(), and it fixes SW_HCD_C_NUM_EPS to be
2 * USBC_MAX_EP_NUM. Thus fixing the sw_hcd0 registration / enable and making
the otg port usable in host mode again.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi_usb: sw_hcd_core_init: Fix a buffer overflow

While looking for the bufferoverflow which was setting sw_hcd->isr to NULL,
I found that if all features are enabled, the aInfo string in sw_hcd_core_init
will overflow. This patch fixes this, and while at it also:
- removes some other unused local variables
- actually prints the carefully build aInfo string
- fixes some glaring coding style issues

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Revert "sunxi_usb-sw_hcd0: Fix overwriting struct sw_hcd memory"

This reverts commit a051008352a0eab3ef24594783de0fe74c0d5759 by
request of the author.

Thanks for merging, your comment made me double check and I'm afraid
my patch titled: "sun4i_usb-sw_hcd0: Fix overwriting struct sw_hcd memory"
is based on me misreading the code. There are n entries in the
mode_4_cfg array, but sw_hcd->endpoints is not addressed by the
i which is iterating over the mode_4_cfg, but instead by
mode_4_cfg[i].hw_ep_num.

This means that fifo_setup and through it USBC_ConfigFifo gets called twice for
each endpoint. But if you trace things further down the call stack, then
USBC_ConfigFifo is a multiplexer function calling USBC_ConfigFifoTx and
USBC_ConfigFifoRx which each set a different set of registers for each function.
so although it seems each ep gets configured twice, it only gets configured once
in a bi-directional manner.

I thought this meant there were separate in/out endpoints per ep address, as that
is how the rest of the world deals with USB endpoints... Anyways.

Conclusion:
1) Floris was completely right, and the stack corruption he found was
   also indirectly corrupting the sw_hcd struct.
2) sw_hcd->endpoints was fine as is.
3) The old ep_config_from_table code was fine wrt its out of bounds checking
   for sw_hcd->endpoints, the only wrong thing in there is this very confusing
   debug print:
     DMSG_DBG_HCD("ep_config_from_table: %s: %d/%d max ep, %d/%d memory\n",
                 sw_hcd_driver_name,
                 n + 1, sw_hcd->config->num_eps * 2 - 1,
                 offset, sw_hcd->config->ram_size);

Which talks about n + 1 versus sw_hcd->config->num_eps * 2 - 1 as endpoint array
usage versus size, which seems wrong to me.

Alejandro, can you please revert my patch titled:
"sun4i_usb-sw_hcd0: Fix overwriting struct sw_hcd memory"

On both 3.0 and 3.4, feel free to use the above as commit message, and to add:

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ata:sw_achi_platform: fix memory corruption when "sata_used" is 0 in script.bin
sun4i_csi: Fixes kernel bug during camera init, v4l field must be set from camera driver response

Just a one line patch that fixes the camera initialization on the
tablets.  I realize the rest of the driver code from allwinner is ugly
as sin, I'll try and submit a style patch later.

Signed-off-by: Neal Peacock <neal@nic-stix.com>
usb: sunxi: register OTG port as 2.0 instead of 1.1
net sun4i_wmac: Drop obsolete poll_controller assignment.

Failed to compile with netconsole enabled. poll_controller is now
only set in the netdeviceops, not in the netdevice itself.
arch:arm:configs:a13_nuclear_defconfig: Fix missing symbols
ERROR: "ve_start" [drivers/media/video/videobuf-dma-contig.ko] undefined!
ERROR: "ve_size" [drivers/media/video/videobuf-dma-contig.ko] undefined!
sun4i-usb: allow USB1.1 devices on OTG USB 2.0 port

When OTG port is USB2.0 type, USB1.1 devices do not work:

[   56.790000] ------------IRQ CONNECT-------------
[   56.790000]
[   56.960000] [sw_hcd]: reset port.
[   57.020000] [sw_hcd]: reset port stopped.
[   57.080000] usb 1-1: new full-speed USB device number 3 using sw_hcd_host0
[   57.080000] usb 1-1: parent hub has no TT
[   57.090000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.100000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.110000] [sw_hcd]: reset port.
[   57.170000] [sw_hcd]: reset port stopped.
[   57.230000] usb 1-1: new full-speed USB device number 4 using sw_hcd_host0
[   57.230000] usb 1-1: parent hub has no TT
[   57.240000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.250000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.250000] [sw_hcd]: reset port.
[   57.320000] [sw_hcd]: reset port stopped.
[   57.380000] usb 1-1: new full-speed USB device number 5 using sw_hcd_host0
[   57.380000] usb 1-1: parent hub has no TT
[   57.390000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.400000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.400000] [sw_hcd]: reset port.
[   57.470000] [sw_hcd]: reset port stopped.
[   57.530000] usb 1-1: new full-speed USB device number 6 using sw_hcd_host0
[   57.530000] usb 1-1: parent hub has no TT
[   57.540000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.540000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   57.550000] hub 1-0:1.0: unable to enumerate USB device on port 1

Enabling .has_tt flag on HCD appears to fix or at least workaround the issue:

[   20.960000] ------------IRQ CONNECT-------------
[   20.960000]
[   21.120000] [sw_hcd]: reset port.
[   21.180000] [sw_hcd]: reset port stopped.
[   21.180000] spurious?
[   21.240000] usb 1-1: new full-speed USB device number 2 using sw_hcd_host0
[   21.240000] [sw_hcd]: reset port.
[   21.300000] [sw_hcd]: reset port stopped.
[   21.360000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   21.360000] [sw_hcd]: sw_hcd_h_disable, epnum = 0
[   21.380000] WRN:L1722(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, STALLING ENDPOINT
[   21.380000] WRN:L1741(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, ep aborting
[   21.390000] WRN:L1722(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, STALLING ENDPOINT
[   21.390000] WRN:L1741(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, ep aborting
[   21.400000] WRN:L1722(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, STALLING ENDPOINT
[   21.400000] WRN:L1741(drivers/usb/sun4i_usb/hcd/core/sw_hcd_host.c):ERR: sw_hcd_h_ep0_irq, ep aborting
[   21.410000] usb 1-1: New USB device found, idVendor=045e, idProduct=0745
[   21.420000] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[   21.420000] usb 1-1: Product: Microsoft\xffffffc2\xffffffae\xffffffae 2.4GHz Transceiver v6.0
[   21.430000] usb 1-1: Manufacturer: Microsoft

Not sure if this is correct or complete fix, as with .has_tt kernel log shows
some warnings. On the other hand, musb uses same flag.

Tested over linux-sunxi-3.4 (+ otg-usb-2.0 patch), compile tested on
linux-sunxi-3.0.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
sunxi-hdmi: Fix Hdmi_mode_support

Hdmi_mode_support translates the past in mode to a CEA-861-D VIC because
Device_Support_VIC should be indexed by a VIC. This patch makes it actually
use the looked up VIC to index Device_Support_VIC.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-hdmi: Add a Hdmi_tv_mode_to_hdmi_mode() helper function

Having the exact same switch-case twice is not really useful.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-hdmi: Simplify audio parameters calculation

All calculations are based on the pixelclock, so instead of this huge
if ... else if ... on the hdmi_mode, simply get the pixel clock from
the mode-table, and use that.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-hdmi: Add 1360x768 mode

Many HD ready but not Full HD LCD tvs have a 1360x768 panel, having this mode
available as hdmi output resolution allows running them at their native
resolution.

Note some tvs have a native resolution of 1366x768, I've tried adding a mode
for that too, and it works, but only with fbcon, X cannot handle the pitch
not being a multiple of 8, and I don't know how to add padding to the
framebuffer, so people should just use 1360x768 with those.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-hdmi: Allow disabling hdmi audio from the kernel cmdline

Disabling hdmi-audio makes things work a lot better with DVI monitors,
as some DVI monitors will mistakenly try to interpret the audio data
as video data.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-disp: Set output-type and output-mode from the kernel cmdline

Because editing uEnv.txt is much simpler / more userfriendly
then dealing with script.bin, and human readable text strings are
way easier to remember then the hardwired mode table.

Note that if the cmdline arguments are not given, or not valid the
fex values are used as a fallback.

Note about the simple_strtol checkpatch warnings, we really want to use
simple_strtol here, as we need the ep to continue parsing after the number.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-disp: Fb_Init: don't assume the lcd driver is always loaded first

Currently the sunxi-disp code depends on the lcd driver always being
loaded first, which is not a good idea. This fixes this. With this it
should be safe to simply build the disp, hdmi and lcd driver into the
kernel (worksforme).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-disp: Remove unused BSP_disp_get_frame_rate function

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-disp: Fix duplication of DISP_SUCCESS and other DISP_XXXX status codes

These were declared (the same) in 2 different header files, causing problems
when both files are included.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-hdmi: s/plus/pulsw/

The "plus" variables store the V/Hsync pulsewidth, so lets give them a more
descriptive name.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>