sunxi-disp: Correct fex file key for sun7i lcd backlight intensity

When support for setting the initial lcd backlight intensity through the fex
file was added to the linux-sunxi tree with commit b243bae3, it was using
lcd#_bright as key.

This is correct for sun4i/sun5i, but the allwinner sources for sun7i are using
lcd#_backlight, they are also using lcd#_bright but as a value for brightness
adjustment by the display enhancement engine. To make things worse, lcd#_bright
has a scale of 0 - 100, so typically has a value of 50, where as lcd#_backlight
has a range of 0-255. This means that for sun7i fex-files which use the offical
lcd#_backlight and lcd#_bright, we take the lcd#_bright value of 50 and
interprete it on a 0-255 scale, we effectively turn the backlight off!

This patch fixes this by properly checking for lcd#_backlight as backlight
intensity setting on sun7i.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
axp152: Add support for power button

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
arm:sunxi:configs: enable axp152 on sun5i_defconfig

Signed-off-by: Alejandro Mery <amery@geeks.cl>
Add CONFIG_SUNXI_EMAC to sun7i_defconfig

Signed-off-by: Davide Soldan <davide.soldan@gmail.com>
sunxi:g2d Rename sun4i_g2d --> sunxi_g2d

Rename drivers/char/sun4i_g2d directory drivers/char/sunxi_g2d
Change all file/directory references from sun4i_g2d to sunxi_g2d
Change all config references from CONFIG_SUN4I_G2D to CONFIG_SUNXI_G2D
Change arch/arm/plat-sunxi/core.c to use IS_ENABLED(CONFIG_SUNXI_G2D)
  instead of defined CONFIG_SUN4I_G2D || defined CONFIG_SUN4I_G2D_MODULE
sunxi:g2d Change from hard-coded interrupt to SW_INT_IRQNO_MP
sunxi:g2d Enable G2D for SUN7I
sunxi-disp: ignore invalid arguments for FBIOPUTCMAP

Just do nothing and return 0 for the unsupported palette indexes
instead of returning -EINVAL. The vesafb and uvesafb drivers do
the same.

Otherwise xf86-video-fbdev or anything else derived from it writes
a lot of "FBIOPUTCMAP: Invalid argument" spam to /var/log/Xorg.0.log
when the X server starts. And apparently also when the screensaver
and/or screen blanking/unblanking kicks in. These error messages
are scaring the users and also distracting attention when doing
real troubleshooting. Not to mention slowing down the X server
startup and wasting extra disk space for storing logs.

Yes, it is ugly to ignore errors. And the right solution would
be to fix the userland code not to use this ioctl with wrong
arguments. But frankly speaking, I don't want to touch the
prehistoric paletted formats in the X server as long as we don't
have a real use case where they can be tested.

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
sunxi-disp: fix UMP framebuffer wrappers when fb0_framebuffer_num > 2

The ioctls GET_UMP_SECURE_ID_BUF1, GET_UMP_SECURE_ID_BUF2 and
GET_UMP_SECURE_ID_SUNXI_FB exist to provide UMP wrappers for the
framebuffer. These ioctls are only used by the x11 flavour of
mali drivers.

In the case if "fb0_framebuffer_num" variable is set to more
than 2 in the fex file, currently we get a misleading
"UMP: Double-buffering not enabled" warning in dmesg.
But with xf86-video-sunxifb it is actually necessary to set
fb0_framebuffer_num to at least 3 for getting real tear-free
zero-copy double buffering for OpenGL ES applications.

The point is that we need space for at least 2 buffers in
the offscreen area to flip between them using the sunxi disp
layers. And the standard x11 desktop also needs some framebuffer
memory, increasing the total number of buffers to 3. For example,
we may have a fullscreen GLES application running with 2 buffers
allocated in the offscreen area, and then suddenly need to show
a popup dialog on top of it. This simply can't be handled
efficiently with fb0_framebuffer_num set to only 2.

Additionally, it turns out that xf86-video-mali actually wants
both GET_UMP_SECURE_ID_BUF1 and GET_UMP_SECURE_ID_BUF2 to
point at the start of the framebuffer (because setting the
second DRI2 buffer to the beginning of the offscreen framebuffer
area is already accomplished by setting the offset in the
DRI2BUFFER structure). The older GET_UMP_SECURE_ID_BUF2 behavior
was unnecessarily changing the base address.

After this patch, GET_UMP_SECURE_ID_BUF1, GET_UMP_SECURE_ID_BUF2
and GET_UMP_SECURE_ID_SUNXI_FB are now all providing
wrappers for the whole framebuffer. And the misleading
"UMP: Double-buffering not enabled" warning is removed.

GET_UMP_SECURE_ID_BUF1 gets assigned secure id 1
GET_UMP_SECURE_ID_BUF2 gets assigned secure id 2
GET_UMP_SECURE_ID_SUNXI_FB gets assigned secure id 3

GET_UMP_SECURE_ID_BUF1 and GET_UMP_SECURE_ID_BUF2 have been
originally used by xf86-video-mali. GET_UMP_SECURE_ID_SUNXI_FB was
earlier added for xf86-video-sunxifb as an extra UMP buffer, which
is not seen as the framebuffer by the Mali blob (the mali blob has
special treatment for secure id 1 and secure id 2 just simply based
on their numbers).

Also for xf86-video-sunxifb we really need two UMP buffers, which
cover the whole framebuffer. So that one of the buffers has
secure id < 3, and another one has secure id >= 3. This secure id
numbers magic is needed to trick the Mali blob in the client process
into requesting the DRI2 buffers again if we detect the back and
front buffers size mismatch. More details can be found in this
commit message:

    https://github.com/ssvb/xf86-video-sunxifb/commit/9e0a87319b90e3e3

V2:
 - GET_UMP_SECURE_ID_BUF2 now also wraps the whole framebuffer as
   this is the right thing to do for xf86-video-mali

Signed-off-by: Siarhei Siamashka <siarhei.siamashka@gmail.com>
Acked-by: Hans de Goede <hdegoede@redhat.com>
sunxi-nand: Only move data to free block when LML_VirtualBlkErase succeeds

Pulled from sun7i NAND driver

Signed-off-by: Patrick Wood <patrickhwood@gmail.com>
sunxi-nand: Added more NAND Flash IDs and code for handling them

New NAND parameters for various manufacturers.
New code for handlind Sandisk NAND
Pulled from sun7i NAND driver

Signed-off-by: Patrick Wood <patrickhwood@gmail.com>
sunxi-nand: Retry code from AW sun7i A20 NAND driver

Pulled retry code from AW A20 NAND code.
Tested on mk802 (Hynix) and Cubieboard A10/A20 (Samsung), but
it's hard to know whether the new code was properly exercised.
Other NAND devices couldn't be tested.

Signed-off-by: Patrick Wood <patrickhwood@gmail.com>
sunxi-nand: add call to PHY_ChangeMode(1) in SCN_AnalyzeNandSystem

It's not clear whether the call to PHY_ChangeMode is required here;
however, the AW sun7i code in SCN_AnalyzeNandSystem has it here,
and SCN_AnalyzeNandSystem is called from init_blklayer in nfd/nand_blk.c
before init_blklayer calls PHY_ChangeMode.

Signed-off-by: Patrick Wood <patrickhwood@gmail.com>
sunxi:emac Make EMAC builds by default as module

Thats commit add sunx's wemac build by default as module when used
on sun4i sun7i sun5i machines.

Signed-off-by: Alexsey Shestacov <wingrime@linux-sunxi.org>
sunxi:disp: Use msleep instead LCD_delay_ms

LCD_delay_ms do same that kernel msleep
This patch remove LCD_delay_ms and use msleep instead.

v2: Use msleep instead msleep_interruptible

Signed-off-by: Alexsey Shestacov <wingrime@linux-sunxi.org>
Acked-by: Jari Helaakoski <tekkuli@gmail.com>
sunxi:disp: Remove LCD_delay_us and use udelay instead

LCD_delay_us only warp around udelay. Better use udelay directly

Signed-off-by: Alexsey Shestacov <wingrime@linux-sunxi.org>
ARM: sunxi: Kconfig: depend on ARCH_SUNxI

The kernel pukes if no ARCH_'s are depended on due to missing plat
stuff. Sun457i all have atleast 1 PWM, only sun4i and sun7i have an AHCI
controller.

Signed-off-by: Oliver Schinagl <oliver@schinagl.nl>
axp209: Fix interrupts on sun7i

The A20 has some extra control registers for the external NMI interrupt
pin, adding the need to be enable and clear it explictly on sun7i.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi-spdif: fix spdif issue for sun7i platform

The problem is that we have not request SP/DIF pin resource

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
sunxi: Fix reboot not working on sun5i

Replace our current watchdog based system reset code with code from the
allwinner sun7i 3.3 sources. This fixes reboot hanging once every 2 attempts
on sun5i (tested on A13 and various A10s based boards). Also tested on A10
and A20 based boards to avoid causing a reboot regression there.

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