a6ed68d646
-----BEGIN PGP SIGNATURE----- iQIcBAABAgAGBQJd3YntAAoJEAx081l5xIa+dcQP/ikABkpm+q23FLKteRpL1rtX xqlg5+KHW+YVCDls2BrINF6vYzyisoa8fNPlKMmOHse/IgMhFe9vBbCj1KQQOUR1 apNycI1wrcw/mn2WDikoIcF6C5cjqK9YVknnYoM6HnF1VmpGd1ecSGrOHrunEkrK cMAWYIeqWGU8Gj/HUOitAFpLWFUMNle0BJuRoGLcoMusgS8yuCIEcpNzRhgL8fvJ bW4imuyv24OjPoQzbKD0oQ0VIP86H0eM4LIeGZ2uyK/BSPKmMDqI4z4isUheS7RL w4a6BdobMIdhew5dBXS0LsUJ3JniVJdHy123q9KgpmQAhGpiNoLT6BujfoUTUeWx Mu0vM8Xmv9n4npdBYC+fLEFQXYJlu9uBA490jP84Kz6Fg1c6GyBebDY7/c2O4Zmg 7pvygmUF6boD6v2sIC/3161crgwU4g8zoxm2V4i9naxes2QB13LiEuJWlaI/FdxY fd3zpglFGdoF1ThNne4QDh6gMKpXvjITyu/QxZeZ67Dt6i0Aqw9cRGHSpiVhYyDc cx2hAp+rDvUi5SHkJKFpVImjB2DDn2xUG2uFMHz0cy9wNg203L3fRDi0hVtnM1+W VpCxyLs2Upz6kEjDRVsfMZ9chCcWAWpVuKhtuuMUDw/IKnbP3uV8kzgJpVpaRVkD 76s5uYWHHBlk1IVlkOUP =Hj7G -----END PGP SIGNATURE----- Merge tag 'drm-next-2019-11-27' of git://anongit.freedesktop.org/drm/drm Pull drm updates from Dave Airlie: "Lots of stuff in here, though it hasn't been too insane this merge apart from dealing with the security fun. uapi: - export different colorspace properties on DP vs HDMI - new fourcc for ARM 16x16 block format - syncobj: allow querying last submitted timeline value - DRM_FORMAT_BIG_ENDIAN defined as unsigned core: - allow using gem vma manager in ttm - connector/encoder/bridge doc fixes - allow more than 3 encoders for a connector - displayport mst suspend/resume reprobing support - vram lazy unmapping, uniform vram mm and gem vram - edid cleanups + AVI informframe bar info - displayport helpers - dpcd parser added dp_cec: - Allow a connector to be associated with a cec device ttm: - pipelining with no_gpu_wait fix - always keep BOs on the LRU sched: - allow free_job routine to sleep i915: - Block userptr from mappable GTT - i915 perf uapi versioning - OA stream dynamic reconfiguration - make context persistence optional - introduce DRM_I915_UNSTABLE Kconfig - add fake lmem testing under unstable - BT.2020 support for DP MSA - struct mutex elimination - Tigerlake display/PLL/power management improvements - Jasper Lake PCH support - refactor PMU for multiple GPUs - Icelake firmware update - Split out vga + switcheroo code amdgpu: - implement dma-buf import/export without helpers - vega20 RAS enablement - DC i2c over aux fixes - renoir GPU reset - DC HDCP support - BACO support for CI/VI asics - MSI-X support - Arcturus EEPROM support - Arcturus VCN encode support - VCN dynamic powergating on RV/RV2 amdkfd: - add navi12/14/renoir support to kfd radeon: - SI dpm fix ported from amdgpu - fix bad DMA on ppc platforms gma500: - memory leak fixes qxl: - convert to new gem mmap exynos: - build warning fix komeda: - add aclk sysfs attribute v3d: - userspace cleanup uapi change i810: - fix for underflow in dispatch ioctls ast: - refactor show_cursor mgag200: - refactor show_cursor arcgpu: - encoder finding improvements mediatek: - mipi_tx, dsi and partial crtc support for MT8183 SoC - rotation support meson: - add suspend/resume support omap: - misc refactors tegra: - DisplayPort support for Tegra 210, 186 and 194. - IOMMU-backed DMA API fixes panfrost: - fix lockdep issue - simplify devfreq integration rcar-du: - R8A774B1 SoC support - fixes for H2 ES2.0 sun4i: - vcc-dsi regulator support virtio-gpu: - vmexit vs spinlock fix - move to gem shmem helpers - handle large command buffers with cma" * tag 'drm-next-2019-11-27' of git://anongit.freedesktop.org/drm/drm: (1855 commits) drm/amdgpu: invalidate mmhub semaphore workaround in gmc9/gmc10 drm/amdgpu: initialize vm_inv_eng0_sem for gfxhub and mmhub drm/amd/amdgpu/sriov skip RLCG s/r list for arcturus VF. drm/amd/amdgpu/sriov temporarily skip ras,dtm,hdcp for arcturus VF drm/amdgpu/gfx10: re-init clear state buffer after gpu reset merge fix for "ftrace: Rework event_create_dir()" drm/amdgpu: Update Arcturus golden registers drm/amdgpu/gfx10: fix out-of-bound mqd_backup array access drm/amdgpu/gfx10: explicitly wait for cp idle after halt/unhalt Revert "drm/amd/display: enable S/G for RAVEN chip" drm/amdgpu: disable gfxoff on original raven drm/amdgpu: remove experimental flag for Navi14 drm/amdgpu: disable gfxoff when using register read interface drm/amdgpu/powerplay: properly set PP_GFXOFF_MASK (v2) drm/amdgpu: fix bad DMA from INTERRUPT_CNTL2 drm/radeon: fix bad DMA from INTERRUPT_CNTL2 drm/amd/display: Fix debugfs on MST connectors drm/amdgpu/nv: add asic func for fetching vbios from rom directly drm/amdgpu: put flush_delayed_work at first drm/amdgpu/vcn2.5: fix the enc loop with hw fini ...
299 lines
6.8 KiB
C
299 lines
6.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright 2017 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/gpio/consumer.h>
|
|
#include <media/cec-notifier.h>
|
|
#include <media/cec-pin.h>
|
|
|
|
struct cec_gpio {
|
|
struct cec_adapter *adap;
|
|
struct cec_notifier *notifier;
|
|
struct device *dev;
|
|
|
|
struct gpio_desc *cec_gpio;
|
|
int cec_irq;
|
|
bool cec_is_low;
|
|
|
|
struct gpio_desc *hpd_gpio;
|
|
int hpd_irq;
|
|
bool hpd_is_high;
|
|
ktime_t hpd_ts;
|
|
|
|
struct gpio_desc *v5_gpio;
|
|
int v5_irq;
|
|
bool v5_is_high;
|
|
ktime_t v5_ts;
|
|
};
|
|
|
|
static bool cec_gpio_read(struct cec_adapter *adap)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
if (cec->cec_is_low)
|
|
return false;
|
|
return gpiod_get_value(cec->cec_gpio);
|
|
}
|
|
|
|
static void cec_gpio_high(struct cec_adapter *adap)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
if (!cec->cec_is_low)
|
|
return;
|
|
cec->cec_is_low = false;
|
|
gpiod_set_value(cec->cec_gpio, 1);
|
|
}
|
|
|
|
static void cec_gpio_low(struct cec_adapter *adap)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
if (cec->cec_is_low)
|
|
return;
|
|
cec->cec_is_low = true;
|
|
gpiod_set_value(cec->cec_gpio, 0);
|
|
}
|
|
|
|
static irqreturn_t cec_hpd_gpio_irq_handler_thread(int irq, void *priv)
|
|
{
|
|
struct cec_gpio *cec = priv;
|
|
|
|
cec_queue_pin_hpd_event(cec->adap, cec->hpd_is_high, cec->hpd_ts);
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static irqreturn_t cec_5v_gpio_irq_handler(int irq, void *priv)
|
|
{
|
|
struct cec_gpio *cec = priv;
|
|
bool is_high = gpiod_get_value(cec->v5_gpio);
|
|
|
|
if (is_high == cec->v5_is_high)
|
|
return IRQ_HANDLED;
|
|
cec->v5_ts = ktime_get();
|
|
cec->v5_is_high = is_high;
|
|
return IRQ_WAKE_THREAD;
|
|
}
|
|
|
|
static irqreturn_t cec_5v_gpio_irq_handler_thread(int irq, void *priv)
|
|
{
|
|
struct cec_gpio *cec = priv;
|
|
|
|
cec_queue_pin_5v_event(cec->adap, cec->v5_is_high, cec->v5_ts);
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static irqreturn_t cec_hpd_gpio_irq_handler(int irq, void *priv)
|
|
{
|
|
struct cec_gpio *cec = priv;
|
|
bool is_high = gpiod_get_value(cec->hpd_gpio);
|
|
|
|
if (is_high == cec->hpd_is_high)
|
|
return IRQ_HANDLED;
|
|
cec->hpd_ts = ktime_get();
|
|
cec->hpd_is_high = is_high;
|
|
return IRQ_WAKE_THREAD;
|
|
}
|
|
|
|
static irqreturn_t cec_gpio_irq_handler(int irq, void *priv)
|
|
{
|
|
struct cec_gpio *cec = priv;
|
|
|
|
cec_pin_changed(cec->adap, gpiod_get_value(cec->cec_gpio));
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static bool cec_gpio_enable_irq(struct cec_adapter *adap)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
enable_irq(cec->cec_irq);
|
|
return true;
|
|
}
|
|
|
|
static void cec_gpio_disable_irq(struct cec_adapter *adap)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
disable_irq(cec->cec_irq);
|
|
}
|
|
|
|
static void cec_gpio_status(struct cec_adapter *adap, struct seq_file *file)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
seq_printf(file, "mode: %s\n", cec->cec_is_low ? "low-drive" : "read");
|
|
seq_printf(file, "using irq: %d\n", cec->cec_irq);
|
|
if (cec->hpd_gpio)
|
|
seq_printf(file, "hpd: %s\n",
|
|
cec->hpd_is_high ? "high" : "low");
|
|
if (cec->v5_gpio)
|
|
seq_printf(file, "5V: %s\n",
|
|
cec->v5_is_high ? "high" : "low");
|
|
}
|
|
|
|
static int cec_gpio_read_hpd(struct cec_adapter *adap)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
if (!cec->hpd_gpio)
|
|
return -ENOTTY;
|
|
return gpiod_get_value(cec->hpd_gpio);
|
|
}
|
|
|
|
static int cec_gpio_read_5v(struct cec_adapter *adap)
|
|
{
|
|
struct cec_gpio *cec = cec_get_drvdata(adap);
|
|
|
|
if (!cec->v5_gpio)
|
|
return -ENOTTY;
|
|
return gpiod_get_value(cec->v5_gpio);
|
|
}
|
|
|
|
static void cec_gpio_free(struct cec_adapter *adap)
|
|
{
|
|
cec_gpio_disable_irq(adap);
|
|
}
|
|
|
|
static const struct cec_pin_ops cec_gpio_pin_ops = {
|
|
.read = cec_gpio_read,
|
|
.low = cec_gpio_low,
|
|
.high = cec_gpio_high,
|
|
.enable_irq = cec_gpio_enable_irq,
|
|
.disable_irq = cec_gpio_disable_irq,
|
|
.status = cec_gpio_status,
|
|
.free = cec_gpio_free,
|
|
.read_hpd = cec_gpio_read_hpd,
|
|
.read_5v = cec_gpio_read_5v,
|
|
};
|
|
|
|
static int cec_gpio_probe(struct platform_device *pdev)
|
|
{
|
|
struct device *dev = &pdev->dev;
|
|
struct device *hdmi_dev;
|
|
struct cec_gpio *cec;
|
|
u32 caps = CEC_CAP_DEFAULTS | CEC_CAP_MONITOR_ALL | CEC_CAP_MONITOR_PIN;
|
|
int ret;
|
|
|
|
hdmi_dev = cec_notifier_parse_hdmi_phandle(dev);
|
|
if (PTR_ERR(hdmi_dev) == -EPROBE_DEFER)
|
|
return PTR_ERR(hdmi_dev);
|
|
if (IS_ERR(hdmi_dev))
|
|
caps |= CEC_CAP_PHYS_ADDR;
|
|
|
|
cec = devm_kzalloc(dev, sizeof(*cec), GFP_KERNEL);
|
|
if (!cec)
|
|
return -ENOMEM;
|
|
|
|
cec->dev = dev;
|
|
|
|
cec->cec_gpio = devm_gpiod_get(dev, "cec", GPIOD_OUT_HIGH_OPEN_DRAIN);
|
|
if (IS_ERR(cec->cec_gpio))
|
|
return PTR_ERR(cec->cec_gpio);
|
|
cec->cec_irq = gpiod_to_irq(cec->cec_gpio);
|
|
|
|
cec->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
|
|
if (IS_ERR(cec->hpd_gpio))
|
|
return PTR_ERR(cec->hpd_gpio);
|
|
|
|
cec->v5_gpio = devm_gpiod_get_optional(dev, "v5", GPIOD_IN);
|
|
if (IS_ERR(cec->v5_gpio))
|
|
return PTR_ERR(cec->v5_gpio);
|
|
|
|
cec->adap = cec_pin_allocate_adapter(&cec_gpio_pin_ops,
|
|
cec, pdev->name, caps);
|
|
if (IS_ERR(cec->adap))
|
|
return PTR_ERR(cec->adap);
|
|
|
|
ret = devm_request_irq(dev, cec->cec_irq, cec_gpio_irq_handler,
|
|
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
|
|
cec->adap->name, cec);
|
|
if (ret)
|
|
goto del_adap;
|
|
|
|
cec_gpio_disable_irq(cec->adap);
|
|
|
|
if (cec->hpd_gpio) {
|
|
cec->hpd_irq = gpiod_to_irq(cec->hpd_gpio);
|
|
ret = devm_request_threaded_irq(dev, cec->hpd_irq,
|
|
cec_hpd_gpio_irq_handler,
|
|
cec_hpd_gpio_irq_handler_thread,
|
|
IRQF_ONESHOT |
|
|
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
|
|
"hpd-gpio", cec);
|
|
if (ret)
|
|
goto del_adap;
|
|
}
|
|
|
|
if (cec->v5_gpio) {
|
|
cec->v5_irq = gpiod_to_irq(cec->v5_gpio);
|
|
ret = devm_request_threaded_irq(dev, cec->v5_irq,
|
|
cec_5v_gpio_irq_handler,
|
|
cec_5v_gpio_irq_handler_thread,
|
|
IRQF_ONESHOT |
|
|
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
|
|
"v5-gpio", cec);
|
|
if (ret)
|
|
goto del_adap;
|
|
}
|
|
|
|
if (!IS_ERR(hdmi_dev)) {
|
|
cec->notifier = cec_notifier_cec_adap_register(hdmi_dev, NULL,
|
|
cec->adap);
|
|
if (!cec->notifier) {
|
|
ret = -ENOMEM;
|
|
goto del_adap;
|
|
}
|
|
}
|
|
|
|
ret = cec_register_adapter(cec->adap, &pdev->dev);
|
|
if (ret)
|
|
goto unreg_notifier;
|
|
|
|
platform_set_drvdata(pdev, cec);
|
|
return 0;
|
|
|
|
unreg_notifier:
|
|
cec_notifier_cec_adap_unregister(cec->notifier, cec->adap);
|
|
del_adap:
|
|
cec_delete_adapter(cec->adap);
|
|
return ret;
|
|
}
|
|
|
|
static int cec_gpio_remove(struct platform_device *pdev)
|
|
{
|
|
struct cec_gpio *cec = platform_get_drvdata(pdev);
|
|
|
|
cec_notifier_cec_adap_unregister(cec->notifier, cec->adap);
|
|
cec_unregister_adapter(cec->adap);
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id cec_gpio_match[] = {
|
|
{
|
|
.compatible = "cec-gpio",
|
|
},
|
|
{},
|
|
};
|
|
MODULE_DEVICE_TABLE(of, cec_gpio_match);
|
|
|
|
static struct platform_driver cec_gpio_pdrv = {
|
|
.probe = cec_gpio_probe,
|
|
.remove = cec_gpio_remove,
|
|
.driver = {
|
|
.name = "cec-gpio",
|
|
.of_match_table = cec_gpio_match,
|
|
},
|
|
};
|
|
|
|
module_platform_driver(cec_gpio_pdrv);
|
|
|
|
MODULE_AUTHOR("Hans Verkuil <hans.verkuil@cisco.com>");
|
|
MODULE_LICENSE("GPL v2");
|
|
MODULE_DESCRIPTION("CEC GPIO driver");
|