Changes in 4.9.185 tracing: Silence GCC 9 array bounds warning gcc-9: silence 'address-of-packed-member' warning scsi: ufs: Avoid runtime suspend possibly being blocked forever usb: chipidea: udc: workaround for endpoint conflict issue IB/hfi1: Silence txreq allocation warnings Input: uinput - add compat ioctl number translation for UI_*_FF_UPLOAD apparmor: enforce nullbyte at end of tag string ARC: fix build warnings with !CONFIG_KPROBES parport: Fix mem leak in parport_register_dev_model parisc: Fix compiler warnings in float emulation code IB/rdmavt: Fix alloc_qpn() WARN_ON() IB/hfi1: Insure freeze_work work_struct is canceled on shutdown IB/{qib, hfi1, rdmavt}: Correct ibv_devinfo max_mr value MIPS: uprobes: remove set but not used variable 'epc' net: dsa: mv88e6xxx: avoid error message on remove from VLAN 0 net: hns: Fix loopback test failed at copper ports sparc: perf: fix updated event period in response to PERF_EVENT_IOC_PERIOD net: ethernet: mediatek: Use hw_feature to judge if HWLRO is supported net: ethernet: mediatek: Use NET_IP_ALIGN to judge if HW RX_2BYTE_OFFSET is enabled drm/arm/hdlcd: Allow a bit of clock tolerance scripts/checkstack.pl: Fix arm64 wrong or unknown architecture scsi: ufs: Check that space was properly alloced in copy_query_response s390/qeth: fix VLAN attribute in bridge_hostnotify udev event hwmon: (pmbus/core) Treat parameters as paged if on multiple pages nvme: Fix u32 overflow in the number of namespace list calculation btrfs: start readahead also in seed devices can: flexcan: fix timeout when set small bitrate can: purge socket error queue on sock destruct powerpc/bpf: use unsigned division instruction for 64-bit operations ARM: imx: cpuidle-imx6sx: Restrict the SW2ISO increase to i.MX6SX Bluetooth: Align minimum encryption key size for LE and BR/EDR connections Bluetooth: Fix regression with minimum encryption key size alignment cfg80211: fix memory leak of wiphy device name mac80211: drop robust management frames from unknown TA mac80211: Do not use stack memory with scatterlist for GMAC IB/hfi1: Avoid hardlockup with flushlist_lock perf ui helpline: Use strlcpy() as a shorter form of strncpy() + explicit set nul perf help: Remove needless use of strncpy() perf header: Fix unchecked usage of strncpy() 9p/rdma: do not disconnect on down_interruptible EAGAIN 9p: acl: fix uninitialized iattr access 9p/rdma: remove useless check in cm_event_handler 9p: p9dirent_read: check network-provided name length net/9p: include trans_common.h to fix missing prototype warning. fs/proc/array.c: allow reporting eip/esp for all coredumping threads fs/binfmt_flat.c: make load_flat_shared_library() work mm/page_idle.c: fix oops because end_pfn is larger than max_pfn scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() x86/speculation: Allow guests to use SSBD even if host does not NFS/flexfiles: Use the correct TCP timeout for flexfiles I/O cpu/speculation: Warn on unsupported mitigations= parameter af_packet: Block execution of tasks waiting for transmit to complete in AF_PACKET net: stmmac: fixed new system time seconds value calculation sctp: change to hold sk after auth shkey is created successfully tipc: change to use register_pernet_device tipc: check msg->req data len in tipc_nl_compat_bearer_disable tun: wake up waitqueues after IFF_UP is set team: Always enable vlan tx offload bonding: Always enable vlan tx offload ipv4: Use return value of inet_iif() for __raw_v4_lookup in the while loop bpf: udp: Avoid calling reuseport's bpf_prog from udp_gro bpf: udp: ipv6: Avoid running reuseport's bpf_prog from __udp6_lib_err tipc: pass tunnel dev as NULL to udp_tunnel(6)_xmit_skb Bluetooth: Fix faulty expression for minimum encryption key size check ASoC : cs4265 : readable register too low ASoC: soc-pcm: BE dai needs prepare when pause release after resume spi: bitbang: Fix NULL pointer dereference in spi_unregister_master drm/mediatek: fix unbind functions ASoC: max98090: remove 24-bit format support if RJ is 0 usb: gadget: fusb300_udc: Fix memory leak of fusb300->ep[i] usb: gadget: udc: lpc32xx: allocate descriptor with GFP_ATOMIC scsi: hpsa: correct ioaccel2 chaining scripts/decode_stacktrace.sh: prefix addr2line with $CROSS_COMPILE mm/mlock.c: change count_mm_mlocked_page_nr return type MIPS: math-emu: do not use bools for arithmetic MIPS: netlogic: xlr: Remove erroneous check in nlm_fmn_send() mfd: omap-usb-tll: Fix register offsets ARC: fix allnoconfig build warning bug.h: work around GCC PR82365 in BUG() ARC: handle gcc generated __builtin_trap for older compiler clk: sunxi: fix uninitialized access KVM: x86: degrade WARN to pr_warn_ratelimited drm/i915/dmc: protect against reading random memory MIPS: Workaround GCC __builtin_unreachable reordering bug ptrace: Fix ->ptracer_cred handling for PTRACE_TRACEME crypto: user - prevent operating on larval algorithms ALSA: seq: fix incorrect order of dest_client/dest_ports arguments ALSA: firewire-lib/fireworks: fix miss detection of received MIDI messages ALSA: line6: Fix write on zero-sized buffer ALSA: usb-audio: fix sign unintended sign extension on left shifts lib/mpi: Fix karactx leak in mpi_powm drm/imx: notify drm core before sending event during crtc disable drm/imx: only send event on crtc disable if kept disabled btrfs: Ensure replaced device doesn't have pending chunk allocation tty: rocket: fix incorrect forward declaration of 'rp_init()' arm64, vdso: Define vdso_{start,end} as array KVM: LAPIC: Fix pending interrupt in IRR blocked by software disable LAPIC IB/hfi1: Close PSM sdma_progress sleep window MIPS: Add missing EHB in mtc0 -> mfc0 sequence. dmaengine: imx-sdma: remove BD_INTR for channel0 arm64: kaslr: keep modules inside module region when KASAN is enabled Linux 4.9.185 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
319 lines
9.4 KiB
C
319 lines
9.4 KiB
C
/*
|
|
* Copyright (C) 2013-2015 ARM Limited
|
|
* Author: Liviu Dudau <Liviu.Dudau@arm.com>
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file COPYING in the main directory of this archive
|
|
* for more details.
|
|
*
|
|
* Implementation of a CRTC class for the HDLCD driver.
|
|
*/
|
|
|
|
#include <drm/drmP.h>
|
|
#include <drm/drm_atomic_helper.h>
|
|
#include <drm/drm_crtc.h>
|
|
#include <drm/drm_crtc_helper.h>
|
|
#include <drm/drm_fb_helper.h>
|
|
#include <drm/drm_fb_cma_helper.h>
|
|
#include <drm/drm_gem_cma_helper.h>
|
|
#include <drm/drm_of.h>
|
|
#include <drm/drm_plane_helper.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/of_graph.h>
|
|
#include <linux/platform_data/simplefb.h>
|
|
#include <video/videomode.h>
|
|
|
|
#include "hdlcd_drv.h"
|
|
#include "hdlcd_regs.h"
|
|
|
|
/*
|
|
* The HDLCD controller is a dumb RGB streamer that gets connected to
|
|
* a single HDMI transmitter or in the case of the ARM Models it gets
|
|
* emulated by the software that does the actual rendering.
|
|
*
|
|
*/
|
|
|
|
static void hdlcd_crtc_cleanup(struct drm_crtc *crtc)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
|
|
|
|
/* stop the controller on cleanup */
|
|
hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0);
|
|
drm_crtc_cleanup(crtc);
|
|
}
|
|
|
|
static const struct drm_crtc_funcs hdlcd_crtc_funcs = {
|
|
.destroy = hdlcd_crtc_cleanup,
|
|
.set_config = drm_atomic_helper_set_config,
|
|
.page_flip = drm_atomic_helper_page_flip,
|
|
.reset = drm_atomic_helper_crtc_reset,
|
|
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
|
|
};
|
|
|
|
static struct simplefb_format supported_formats[] = SIMPLEFB_FORMATS;
|
|
|
|
/*
|
|
* Setup the HDLCD registers for decoding the pixels out of the framebuffer
|
|
*/
|
|
static int hdlcd_set_pxl_fmt(struct drm_crtc *crtc)
|
|
{
|
|
unsigned int btpp;
|
|
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
|
|
uint32_t pixel_format;
|
|
struct simplefb_format *format = NULL;
|
|
int i;
|
|
|
|
pixel_format = crtc->primary->state->fb->pixel_format;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(supported_formats); i++) {
|
|
if (supported_formats[i].fourcc == pixel_format)
|
|
format = &supported_formats[i];
|
|
}
|
|
|
|
if (WARN_ON(!format))
|
|
return 0;
|
|
|
|
/* HDLCD uses 'bytes per pixel', zero means 1 byte */
|
|
btpp = (format->bits_per_pixel + 7) / 8;
|
|
hdlcd_write(hdlcd, HDLCD_REG_PIXEL_FORMAT, (btpp - 1) << 3);
|
|
|
|
/*
|
|
* The format of the HDLCD_REG_<color>_SELECT register is:
|
|
* - bits[23:16] - default value for that color component
|
|
* - bits[11:8] - number of bits to extract for each color component
|
|
* - bits[4:0] - index of the lowest bit to extract
|
|
*
|
|
* The default color value is used when bits[11:8] are zero, when the
|
|
* pixel is outside the visible frame area or when there is a
|
|
* buffer underrun.
|
|
*/
|
|
hdlcd_write(hdlcd, HDLCD_REG_RED_SELECT, format->red.offset |
|
|
#ifdef CONFIG_DRM_HDLCD_SHOW_UNDERRUN
|
|
0x00ff0000 | /* show underruns in red */
|
|
#endif
|
|
((format->red.length & 0xf) << 8));
|
|
hdlcd_write(hdlcd, HDLCD_REG_GREEN_SELECT, format->green.offset |
|
|
((format->green.length & 0xf) << 8));
|
|
hdlcd_write(hdlcd, HDLCD_REG_BLUE_SELECT, format->blue.offset |
|
|
((format->blue.length & 0xf) << 8));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void hdlcd_crtc_mode_set_nofb(struct drm_crtc *crtc)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
|
|
struct drm_display_mode *m = &crtc->state->adjusted_mode;
|
|
struct videomode vm;
|
|
unsigned int polarities, err;
|
|
|
|
vm.vfront_porch = m->crtc_vsync_start - m->crtc_vdisplay;
|
|
vm.vback_porch = m->crtc_vtotal - m->crtc_vsync_end;
|
|
vm.vsync_len = m->crtc_vsync_end - m->crtc_vsync_start;
|
|
vm.hfront_porch = m->crtc_hsync_start - m->crtc_hdisplay;
|
|
vm.hback_porch = m->crtc_htotal - m->crtc_hsync_end;
|
|
vm.hsync_len = m->crtc_hsync_end - m->crtc_hsync_start;
|
|
|
|
polarities = HDLCD_POLARITY_DATAEN | HDLCD_POLARITY_DATA;
|
|
|
|
if (m->flags & DRM_MODE_FLAG_PHSYNC)
|
|
polarities |= HDLCD_POLARITY_HSYNC;
|
|
if (m->flags & DRM_MODE_FLAG_PVSYNC)
|
|
polarities |= HDLCD_POLARITY_VSYNC;
|
|
|
|
/* Allow max number of outstanding requests and largest burst size */
|
|
hdlcd_write(hdlcd, HDLCD_REG_BUS_OPTIONS,
|
|
HDLCD_BUS_MAX_OUTSTAND | HDLCD_BUS_BURST_16);
|
|
|
|
hdlcd_write(hdlcd, HDLCD_REG_V_DATA, m->crtc_vdisplay - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_V_BACK_PORCH, vm.vback_porch - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_V_FRONT_PORCH, vm.vfront_porch - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_V_SYNC, vm.vsync_len - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_H_DATA, m->crtc_hdisplay - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_H_BACK_PORCH, vm.hback_porch - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_H_FRONT_PORCH, vm.hfront_porch - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_H_SYNC, vm.hsync_len - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_POLARITIES, polarities);
|
|
|
|
err = hdlcd_set_pxl_fmt(crtc);
|
|
if (err)
|
|
return;
|
|
|
|
clk_set_rate(hdlcd->clk, m->crtc_clock * 1000);
|
|
}
|
|
|
|
static void hdlcd_crtc_enable(struct drm_crtc *crtc)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
|
|
|
|
clk_prepare_enable(hdlcd->clk);
|
|
hdlcd_crtc_mode_set_nofb(crtc);
|
|
hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 1);
|
|
drm_crtc_vblank_on(crtc);
|
|
}
|
|
|
|
static void hdlcd_crtc_disable(struct drm_crtc *crtc)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
|
|
|
|
drm_crtc_vblank_off(crtc);
|
|
hdlcd_write(hdlcd, HDLCD_REG_COMMAND, 0);
|
|
clk_disable_unprepare(hdlcd->clk);
|
|
}
|
|
|
|
static int hdlcd_crtc_atomic_check(struct drm_crtc *crtc,
|
|
struct drm_crtc_state *state)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd = crtc_to_hdlcd_priv(crtc);
|
|
struct drm_display_mode *mode = &state->adjusted_mode;
|
|
long rate, clk_rate = mode->clock * 1000;
|
|
|
|
rate = clk_round_rate(hdlcd->clk, clk_rate);
|
|
/* 0.1% seems a close enough tolerance for the TDA19988 on Juno */
|
|
if (abs(rate - clk_rate) * 1000 > clk_rate) {
|
|
/* clock required by mode not supported by hardware */
|
|
return -EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void hdlcd_crtc_atomic_begin(struct drm_crtc *crtc,
|
|
struct drm_crtc_state *state)
|
|
{
|
|
struct drm_pending_vblank_event *event = crtc->state->event;
|
|
|
|
if (event) {
|
|
crtc->state->event = NULL;
|
|
|
|
spin_lock_irq(&crtc->dev->event_lock);
|
|
if (drm_crtc_vblank_get(crtc) == 0)
|
|
drm_crtc_arm_vblank_event(crtc, event);
|
|
else
|
|
drm_crtc_send_vblank_event(crtc, event);
|
|
spin_unlock_irq(&crtc->dev->event_lock);
|
|
}
|
|
}
|
|
|
|
static const struct drm_crtc_helper_funcs hdlcd_crtc_helper_funcs = {
|
|
.enable = hdlcd_crtc_enable,
|
|
.disable = hdlcd_crtc_disable,
|
|
.atomic_check = hdlcd_crtc_atomic_check,
|
|
.atomic_begin = hdlcd_crtc_atomic_begin,
|
|
};
|
|
|
|
static int hdlcd_plane_atomic_check(struct drm_plane *plane,
|
|
struct drm_plane_state *state)
|
|
{
|
|
u32 src_w, src_h;
|
|
|
|
src_w = state->src_w >> 16;
|
|
src_h = state->src_h >> 16;
|
|
|
|
/* we can't do any scaling of the plane source */
|
|
if ((src_w != state->crtc_w) || (src_h != state->crtc_h))
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void hdlcd_plane_atomic_update(struct drm_plane *plane,
|
|
struct drm_plane_state *state)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd;
|
|
struct drm_gem_cma_object *gem;
|
|
unsigned int depth, bpp;
|
|
u32 src_w, src_h, dest_w, dest_h;
|
|
dma_addr_t scanout_start;
|
|
|
|
if (!plane->state->fb)
|
|
return;
|
|
|
|
drm_fb_get_bpp_depth(plane->state->fb->pixel_format, &depth, &bpp);
|
|
src_w = plane->state->src_w >> 16;
|
|
src_h = plane->state->src_h >> 16;
|
|
dest_w = plane->state->crtc_w;
|
|
dest_h = plane->state->crtc_h;
|
|
gem = drm_fb_cma_get_gem_obj(plane->state->fb, 0);
|
|
scanout_start = gem->paddr + plane->state->fb->offsets[0] +
|
|
plane->state->crtc_y * plane->state->fb->pitches[0] +
|
|
plane->state->crtc_x * bpp / 8;
|
|
|
|
hdlcd = plane->dev->dev_private;
|
|
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_LENGTH, plane->state->fb->pitches[0]);
|
|
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_PITCH, plane->state->fb->pitches[0]);
|
|
hdlcd_write(hdlcd, HDLCD_REG_FB_LINE_COUNT, dest_h - 1);
|
|
hdlcd_write(hdlcd, HDLCD_REG_FB_BASE, scanout_start);
|
|
}
|
|
|
|
static const struct drm_plane_helper_funcs hdlcd_plane_helper_funcs = {
|
|
.atomic_check = hdlcd_plane_atomic_check,
|
|
.atomic_update = hdlcd_plane_atomic_update,
|
|
};
|
|
|
|
static void hdlcd_plane_destroy(struct drm_plane *plane)
|
|
{
|
|
drm_plane_helper_disable(plane);
|
|
drm_plane_cleanup(plane);
|
|
}
|
|
|
|
static const struct drm_plane_funcs hdlcd_plane_funcs = {
|
|
.update_plane = drm_atomic_helper_update_plane,
|
|
.disable_plane = drm_atomic_helper_disable_plane,
|
|
.destroy = hdlcd_plane_destroy,
|
|
.reset = drm_atomic_helper_plane_reset,
|
|
.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
|
|
.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
|
|
};
|
|
|
|
static struct drm_plane *hdlcd_plane_init(struct drm_device *drm)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd = drm->dev_private;
|
|
struct drm_plane *plane = NULL;
|
|
u32 formats[ARRAY_SIZE(supported_formats)], i;
|
|
int ret;
|
|
|
|
plane = devm_kzalloc(drm->dev, sizeof(*plane), GFP_KERNEL);
|
|
if (!plane)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(supported_formats); i++)
|
|
formats[i] = supported_formats[i].fourcc;
|
|
|
|
ret = drm_universal_plane_init(drm, plane, 0xff, &hdlcd_plane_funcs,
|
|
formats, ARRAY_SIZE(formats),
|
|
DRM_PLANE_TYPE_PRIMARY, NULL);
|
|
if (ret) {
|
|
devm_kfree(drm->dev, plane);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
drm_plane_helper_add(plane, &hdlcd_plane_helper_funcs);
|
|
hdlcd->plane = plane;
|
|
|
|
return plane;
|
|
}
|
|
|
|
int hdlcd_setup_crtc(struct drm_device *drm)
|
|
{
|
|
struct hdlcd_drm_private *hdlcd = drm->dev_private;
|
|
struct drm_plane *primary;
|
|
int ret;
|
|
|
|
primary = hdlcd_plane_init(drm);
|
|
if (IS_ERR(primary))
|
|
return PTR_ERR(primary);
|
|
|
|
ret = drm_crtc_init_with_planes(drm, &hdlcd->crtc, primary, NULL,
|
|
&hdlcd_crtc_funcs, NULL);
|
|
if (ret) {
|
|
hdlcd_plane_destroy(primary);
|
|
devm_kfree(drm->dev, primary);
|
|
return ret;
|
|
}
|
|
|
|
drm_crtc_helper_add(&hdlcd->crtc, &hdlcd_crtc_helper_funcs);
|
|
return 0;
|
|
}
|