Initial accel subsystem support. There are no drivers yet, just the framework. New driver: - ofdrm - replacement for offb fbdev: - add support for nomodeset fourcc: - add Vivante tiled modifier core: - atomic-helpers: CRTC primary plane test fixes, fb access hooks - connector: TV API consistency, cmdline parser improvements - send connector hotplug on cleanup - sort makefile objects tests: - sort kunit tests - improve DP-MST tests - add kunit helpers to create a device sched: - module param for scheduling policy - refcounting fix buddy: - add back random seed log ttm: - convert ttm_resource to size_t - optimize pool allocations edid: - HFVSDB parsing support fixes - logging/debug improvements - DSC quirks dma-buf: - Add unlocked vmap and attachment mapping - move drivers to common locking convention - locking improvements firmware: - new API for rPI firmware and vc4 xilinx: - zynqmp: displayport bridge support - dpsub fix bridge: - adv7533: Remove dynamic lane switching - it6505: Runtime PM support, sync improvements - ps8640: Handle AUX defer messages - tc358775: Drop soft-reset over I2C panel: - panel-edp: Add INX N116BGE-EA2 C2 and C4 support. - Jadard JD9365DA-H3 - NewVision NV3051D amdgpu: - DCN support on ARM - DCN 2.1 secure display - Sienna Cichlid mode2 reset fixes - new GC 11.x firmware versions - drop AMD specific DSC workarounds in favour of drm code - clang warning fixes - scheduler rework - SR-IOV fixes - GPUVM locking fixes - fix memory leak in CS IOCTL error path - flexible array updates - enable new GC/PSP/SMU/NBIO IP - GFX preemption support for gfx9 amdkfd: - cache size fixes - userptr fixes - enable cooperative launch on gfx 10.3 - enable GC 11.0.4 KFD support radeon: - replace kmap with kmap_local_page - ACPI ref count fix - HDA audio notifier support i915: - DG2 enabled by default - MTL enablement work - hotplug refactoring - VBT improvements - Display and watermark refactoring - ADL-P workaround - temp disable runtime_pm for discrete- - fix for A380 as a secondary GPU - Wa_18017747507 for DG2 - CS timestamp support fixes for gen5 and earlier - never purge busy TTM objects - use i915_sg_dma_sizes for all backends - demote GuC kernel contexts to normal priority - gvt: refactor for new MDEV interface - enable DC power states on eDP ports - fix gen 2/3 workarounds nouveau: - fix page fault handling - Ampere acceleration support - driver stability improvements - nva3 backlight support msm: - MSM_INFO_GET_FLAGS support - DPU: XR30 and P010 image formats - Qualcomm SM6115 support - DSI PHY support for QCM2290 - HDMI: refactored dev init path - remove exclusive-fence hack - fix speed-bin detection - enable clamp to idle on 7c3 - improved hangcheck detection vmwgfx: - fb and cursor refactoring - convert to generic hashtable - cursor improvements etnaviv: - hw workarounds - softpin MMU fixes ast: - atomic gamma LUT support - convert to SHMEM lcdif: - support YUV planes - Increase DMA burst size - FIFO threshold tuning meson: - fix return type of cvbs mode_valid mgag200: - fix PLL setup on some revisions sun4i: - A100 and D1 support udl: - modesetting improvements - hot unplug support vc4: - support PAL-M - fix regression preventing 4K @ 60Hz - fix NULL ptr deref v3d: - switch to drm managed resources renesas: - RZ/G2L DSI support - DU Kconfig cleanup mediatek: - fixup dpi and hdmi - MT8188 dpi support - MT8195 AFBC support tegra: - NVDEC hardware on Tegra234 SoC hdlcd: - switch to drm managed resources ingenic: - fix registration error path hisilicon: - convert to drm_mode_init maildp: - use managed resources mtk: - use drm_mode_init rockchip: - use drm_mode_copy -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEEKbZHaGwW9KfbeusDHTzWXnEhr4FAmOXxI0ACgkQDHTzWXnE hr4NyBAAojK3N+XJf2b8LWuRKsShCr5FXlteEDxiYGLeB8/g4x3LztSfHgUg0iuS nP1m7Cx4snXcVNS6iyOsoZVq1EGUAWvv+mPWJe1UywjpyqtciTVQ11GEHRvI/w+V GRvkhmt/TsoZA0QIlS2MaOmhn9j17QOcuYTUjYdyRL4tsrHWrTASH5W1Jt2xmDyw 5FUJvfukPWm100DVWbh6hWbCKL22bDDF/nj1H+G6hYSyTjVbk7wZ0vy2m6TnIHNF iyBHBIzFPg3BveiSlKe6aVX7Gq2d8bfqjHsgN5f1qcS4ejWEkHLVxJtBdOB+fOSC 7o8Ms7WHi1AmnkOVCGRIjJ0cJrLZu2HDlyhViguAO1XQ3Jvuo/4WW3mplv+YPOMc c+P/zuPG42d4lrISuB8wspTdOgxmqpZDkg3HE6n1+jiVR0u4hTTYktoPnLsHX6KG l/l2B6aVAxE4b6P0q3ofYoAnk5rNsb1YUS+a8kC6f97TQ3gmOsN75iZXD/ASHg2r ozhh2wcFxIPkJhE7vqLWPIBCWQs93sGyQXoI7Q0TJaIAZTXV0VmO1BIofetpVImE 7FhDC4wvBedXywN8NYUEFbCTOnIcDMteM/i6S1ns78s5UjDa5osPuS5I02VT1lbN tvnJoHNkhCt13lJz63b0HNFm3cPKoRosCQhJeshyUYaFKs+evL0= =pABG -----END PGP SIGNATURE----- Merge tag 'drm-next-2022-12-13' of git://anongit.freedesktop.org/drm/drm Pull drm updates from Dave Airlie: "The biggest highlight is that the accel subsystem framework is merged. Hopefully for 6.3 we will be able to line up a driver to use it. In drivers land, i915 enables DG2 support by default now, and nouveau has a big stability refactoring and initial ampere support, AMD includes new hw IP support and should build on ARM again. There is also an ofdrm driver to take over offb on platforms it's used. Stuff outside my tree, the dma-buf patches hit a few places, the vc4 firmware changes also do, and i915 has some interactions with MEI for discrete GPUs. I think all of those should have been acked/reviewed by relevant parties. New driver: - ofdrm - replacement for offb fbdev: - add support for nomodeset fourcc: - add Vivante tiled modifier core: - atomic-helpers: CRTC primary plane test fixes, fb access hooks - connector: TV API consistency, cmdline parser improvements - send connector hotplug on cleanup - sort makefile objects tests: - sort kunit tests - improve DP-MST tests - add kunit helpers to create a device sched: - module param for scheduling policy - refcounting fix buddy: - add back random seed log ttm: - convert ttm_resource to size_t - optimize pool allocations edid: - HFVSDB parsing support fixes - logging/debug improvements - DSC quirks dma-buf: - Add unlocked vmap and attachment mapping - move drivers to common locking convention - locking improvements firmware: - new API for rPI firmware and vc4 xilinx: - zynqmp: displayport bridge support - dpsub fix bridge: - adv7533: Remove dynamic lane switching - it6505: Runtime PM support, sync improvements - ps8640: Handle AUX defer messages - tc358775: Drop soft-reset over I2C panel: - panel-edp: Add INX N116BGE-EA2 C2 and C4 support. - Jadard JD9365DA-H3 - NewVision NV3051D amdgpu: - DCN support on ARM - DCN 2.1 secure display - Sienna Cichlid mode2 reset fixes - new GC 11.x firmware versions - drop AMD specific DSC workarounds in favour of drm code - clang warning fixes - scheduler rework - SR-IOV fixes - GPUVM locking fixes - fix memory leak in CS IOCTL error path - flexible array updates - enable new GC/PSP/SMU/NBIO IP - GFX preemption support for gfx9 amdkfd: - cache size fixes - userptr fixes - enable cooperative launch on gfx 10.3 - enable GC 11.0.4 KFD support radeon: - replace kmap with kmap_local_page - ACPI ref count fix - HDA audio notifier support i915: - DG2 enabled by default - MTL enablement work - hotplug refactoring - VBT improvements - Display and watermark refactoring - ADL-P workaround - temp disable runtime_pm for discrete- - fix for A380 as a secondary GPU - Wa_18017747507 for DG2 - CS timestamp support fixes for gen5 and earlier - never purge busy TTM objects - use i915_sg_dma_sizes for all backends - demote GuC kernel contexts to normal priority - gvt: refactor for new MDEV interface - enable DC power states on eDP ports - fix gen 2/3 workarounds nouveau: - fix page fault handling - Ampere acceleration support - driver stability improvements - nva3 backlight support msm: - MSM_INFO_GET_FLAGS support - DPU: XR30 and P010 image formats - Qualcomm SM6115 support - DSI PHY support for QCM2290 - HDMI: refactored dev init path - remove exclusive-fence hack - fix speed-bin detection - enable clamp to idle on 7c3 - improved hangcheck detection vmwgfx: - fb and cursor refactoring - convert to generic hashtable - cursor improvements etnaviv: - hw workarounds - softpin MMU fixes ast: - atomic gamma LUT support - convert to SHMEM lcdif: - support YUV planes - Increase DMA burst size - FIFO threshold tuning meson: - fix return type of cvbs mode_valid mgag200: - fix PLL setup on some revisions sun4i: - A100 and D1 support udl: - modesetting improvements - hot unplug support vc4: - support PAL-M - fix regression preventing 4K @ 60Hz - fix NULL ptr deref v3d: - switch to drm managed resources renesas: - RZ/G2L DSI support - DU Kconfig cleanup mediatek: - fixup dpi and hdmi - MT8188 dpi support - MT8195 AFBC support tegra: - NVDEC hardware on Tegra234 SoC hdlcd: - switch to drm managed resources ingenic: - fix registration error path hisilicon: - convert to drm_mode_init maildp: - use managed resources mtk: - use drm_mode_init rockchip: - use drm_mode_copy" * tag 'drm-next-2022-12-13' of git://anongit.freedesktop.org/drm/drm: (1397 commits) drm/amdgpu: fix mmhub register base coding error drm/amdgpu: add tmz support for GC IP v11.0.4 drm/amdgpu: enable GFX Clock Gating control for GC IP v11.0.4 drm/amdgpu: enable GFX Power Gating for GC IP v11.0.4 drm/amdgpu: enable GFX IP v11.0.4 CG support drm/amdgpu: Make amdgpu_ring_mux functions as static drm/amdgpu: generally allow over-commit during BO allocation drm/amd/display: fix array index out of bound error in DCN32 DML drm/amd/display: 3.2.215 drm/amd/display: set optimized required for comp buf changes drm/amd/display: Add debug option to skip PSR CRTC disable drm/amd/display: correct DML calc error of UrgentLatency drm/amd/display: correct static_screen_event_mask drm/amd/display: Ensure commit_streams returns the DC return code drm/amd/display: read invalid ddc pin status cause engine busy drm/amd/display: Bypass DET swath fill check for max clocks drm/amd/display: Disable uclk pstate for subvp pipes drm/amd/display: Fix DCN2.1 default DSC clocks drm/amd/display: Enable dp_hdmi21_pcon support drm/amd/display: prevent seamless boot on displays that don't have the preferred dig ...
411 lines
10 KiB
C
411 lines
10 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Defines interfaces for interacting with the Raspberry Pi firmware's
|
|
* property channel.
|
|
*
|
|
* Copyright © 2015 Broadcom
|
|
*/
|
|
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/kref.h>
|
|
#include <linux/mailbox_client.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of_platform.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
#include <soc/bcm2835/raspberrypi-firmware.h>
|
|
|
|
#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
|
|
#define MBOX_CHAN(msg) ((msg) & 0xf)
|
|
#define MBOX_DATA28(msg) ((msg) & ~0xf)
|
|
#define MBOX_CHAN_PROPERTY 8
|
|
|
|
static struct platform_device *rpi_hwmon;
|
|
static struct platform_device *rpi_clk;
|
|
|
|
struct rpi_firmware {
|
|
struct mbox_client cl;
|
|
struct mbox_chan *chan; /* The property channel. */
|
|
struct completion c;
|
|
u32 enabled;
|
|
|
|
struct kref consumers;
|
|
};
|
|
|
|
static DEFINE_MUTEX(transaction_lock);
|
|
|
|
static void response_callback(struct mbox_client *cl, void *msg)
|
|
{
|
|
struct rpi_firmware *fw = container_of(cl, struct rpi_firmware, cl);
|
|
complete(&fw->c);
|
|
}
|
|
|
|
/*
|
|
* Sends a request to the firmware through the BCM2835 mailbox driver,
|
|
* and synchronously waits for the reply.
|
|
*/
|
|
static int
|
|
rpi_firmware_transaction(struct rpi_firmware *fw, u32 chan, u32 data)
|
|
{
|
|
u32 message = MBOX_MSG(chan, data);
|
|
int ret;
|
|
|
|
WARN_ON(data & 0xf);
|
|
|
|
mutex_lock(&transaction_lock);
|
|
reinit_completion(&fw->c);
|
|
ret = mbox_send_message(fw->chan, &message);
|
|
if (ret >= 0) {
|
|
if (wait_for_completion_timeout(&fw->c, HZ)) {
|
|
ret = 0;
|
|
} else {
|
|
ret = -ETIMEDOUT;
|
|
WARN_ONCE(1, "Firmware transaction timeout");
|
|
}
|
|
} else {
|
|
dev_err(fw->cl.dev, "mbox_send_message returned %d\n", ret);
|
|
}
|
|
mutex_unlock(&transaction_lock);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* rpi_firmware_property_list - Submit firmware property list
|
|
* @fw: Pointer to firmware structure from rpi_firmware_get().
|
|
* @data: Buffer holding tags.
|
|
* @tag_size: Size of tags buffer.
|
|
*
|
|
* Submits a set of concatenated tags to the VPU firmware through the
|
|
* mailbox property interface.
|
|
*
|
|
* The buffer header and the ending tag are added by this function and
|
|
* don't need to be supplied, just the actual tags for your operation.
|
|
* See struct rpi_firmware_property_tag_header for the per-tag
|
|
* structure.
|
|
*/
|
|
int rpi_firmware_property_list(struct rpi_firmware *fw,
|
|
void *data, size_t tag_size)
|
|
{
|
|
size_t size = tag_size + 12;
|
|
u32 *buf;
|
|
dma_addr_t bus_addr;
|
|
int ret;
|
|
|
|
/* Packets are processed a dword at a time. */
|
|
if (size & 3)
|
|
return -EINVAL;
|
|
|
|
buf = dma_alloc_coherent(fw->cl.dev, PAGE_ALIGN(size), &bus_addr,
|
|
GFP_ATOMIC);
|
|
if (!buf)
|
|
return -ENOMEM;
|
|
|
|
/* The firmware will error out without parsing in this case. */
|
|
WARN_ON(size >= 1024 * 1024);
|
|
|
|
buf[0] = size;
|
|
buf[1] = RPI_FIRMWARE_STATUS_REQUEST;
|
|
memcpy(&buf[2], data, tag_size);
|
|
buf[size / 4 - 1] = RPI_FIRMWARE_PROPERTY_END;
|
|
wmb();
|
|
|
|
ret = rpi_firmware_transaction(fw, MBOX_CHAN_PROPERTY, bus_addr);
|
|
|
|
rmb();
|
|
memcpy(data, &buf[2], tag_size);
|
|
if (ret == 0 && buf[1] != RPI_FIRMWARE_STATUS_SUCCESS) {
|
|
/*
|
|
* The tag name here might not be the one causing the
|
|
* error, if there were multiple tags in the request.
|
|
* But single-tag is the most common, so go with it.
|
|
*/
|
|
dev_err(fw->cl.dev, "Request 0x%08x returned status 0x%08x\n",
|
|
buf[2], buf[1]);
|
|
ret = -EINVAL;
|
|
}
|
|
|
|
dma_free_coherent(fw->cl.dev, PAGE_ALIGN(size), buf, bus_addr);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(rpi_firmware_property_list);
|
|
|
|
/**
|
|
* rpi_firmware_property - Submit single firmware property
|
|
* @fw: Pointer to firmware structure from rpi_firmware_get().
|
|
* @tag: One of enum_mbox_property_tag.
|
|
* @tag_data: Tag data buffer.
|
|
* @buf_size: Buffer size.
|
|
*
|
|
* Submits a single tag to the VPU firmware through the mailbox
|
|
* property interface.
|
|
*
|
|
* This is a convenience wrapper around
|
|
* rpi_firmware_property_list() to avoid some of the
|
|
* boilerplate in property calls.
|
|
*/
|
|
int rpi_firmware_property(struct rpi_firmware *fw,
|
|
u32 tag, void *tag_data, size_t buf_size)
|
|
{
|
|
struct rpi_firmware_property_tag_header *header;
|
|
int ret;
|
|
|
|
/* Some mailboxes can use over 1k bytes. Rather than checking
|
|
* size and using stack or kmalloc depending on requirements,
|
|
* just use kmalloc. Mailboxes don't get called enough to worry
|
|
* too much about the time taken in the allocation.
|
|
*/
|
|
void *data = kmalloc(sizeof(*header) + buf_size, GFP_KERNEL);
|
|
|
|
if (!data)
|
|
return -ENOMEM;
|
|
|
|
header = data;
|
|
header->tag = tag;
|
|
header->buf_size = buf_size;
|
|
header->req_resp_size = 0;
|
|
memcpy(data + sizeof(*header), tag_data, buf_size);
|
|
|
|
ret = rpi_firmware_property_list(fw, data, buf_size + sizeof(*header));
|
|
|
|
memcpy(tag_data, data + sizeof(*header), buf_size);
|
|
|
|
kfree(data);
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(rpi_firmware_property);
|
|
|
|
static void
|
|
rpi_firmware_print_firmware_revision(struct rpi_firmware *fw)
|
|
{
|
|
time64_t date_and_time;
|
|
u32 packet;
|
|
int ret = rpi_firmware_property(fw,
|
|
RPI_FIRMWARE_GET_FIRMWARE_REVISION,
|
|
&packet, sizeof(packet));
|
|
|
|
if (ret)
|
|
return;
|
|
|
|
/* This is not compatible with y2038 */
|
|
date_and_time = packet;
|
|
dev_info(fw->cl.dev, "Attached to firmware from %ptT\n", &date_and_time);
|
|
}
|
|
|
|
static void
|
|
rpi_register_hwmon_driver(struct device *dev, struct rpi_firmware *fw)
|
|
{
|
|
u32 packet;
|
|
int ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_THROTTLED,
|
|
&packet, sizeof(packet));
|
|
|
|
if (ret)
|
|
return;
|
|
|
|
rpi_hwmon = platform_device_register_data(dev, "raspberrypi-hwmon",
|
|
-1, NULL, 0);
|
|
}
|
|
|
|
static void rpi_register_clk_driver(struct device *dev)
|
|
{
|
|
struct device_node *firmware;
|
|
|
|
/*
|
|
* Earlier DTs don't have a node for the firmware clocks but
|
|
* rely on us creating a platform device by hand. If we do
|
|
* have a node for the firmware clocks, just bail out here.
|
|
*/
|
|
firmware = of_get_compatible_child(dev->of_node,
|
|
"raspberrypi,firmware-clocks");
|
|
if (firmware) {
|
|
of_node_put(firmware);
|
|
return;
|
|
}
|
|
|
|
rpi_clk = platform_device_register_data(dev, "raspberrypi-clk",
|
|
-1, NULL, 0);
|
|
}
|
|
|
|
unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw, unsigned int id)
|
|
{
|
|
struct rpi_firmware_clk_rate_request msg =
|
|
RPI_FIRMWARE_CLK_RATE_REQUEST(id);
|
|
int ret;
|
|
|
|
ret = rpi_firmware_property(fw, RPI_FIRMWARE_GET_MAX_CLOCK_RATE,
|
|
&msg, sizeof(msg));
|
|
if (ret)
|
|
/*
|
|
* If our firmware doesn't support that operation, or fails, we
|
|
* assume the maximum clock rate is absolute maximum we can
|
|
* store over our type.
|
|
*/
|
|
return UINT_MAX;
|
|
|
|
return le32_to_cpu(msg.rate);
|
|
}
|
|
EXPORT_SYMBOL_GPL(rpi_firmware_clk_get_max_rate);
|
|
|
|
static void rpi_firmware_delete(struct kref *kref)
|
|
{
|
|
struct rpi_firmware *fw = container_of(kref, struct rpi_firmware,
|
|
consumers);
|
|
|
|
mbox_free_channel(fw->chan);
|
|
kfree(fw);
|
|
}
|
|
|
|
void rpi_firmware_put(struct rpi_firmware *fw)
|
|
{
|
|
kref_put(&fw->consumers, rpi_firmware_delete);
|
|
}
|
|
EXPORT_SYMBOL_GPL(rpi_firmware_put);
|
|
|
|
static void devm_rpi_firmware_put(void *data)
|
|
{
|
|
struct rpi_firmware *fw = data;
|
|
|
|
rpi_firmware_put(fw);
|
|
}
|
|
|
|
static int rpi_firmware_probe(struct platform_device *pdev)
|
|
{
|
|
struct device *dev = &pdev->dev;
|
|
struct rpi_firmware *fw;
|
|
|
|
/*
|
|
* Memory will be freed by rpi_firmware_delete() once all users have
|
|
* released their firmware handles. Don't use devm_kzalloc() here.
|
|
*/
|
|
fw = kzalloc(sizeof(*fw), GFP_KERNEL);
|
|
if (!fw)
|
|
return -ENOMEM;
|
|
|
|
fw->cl.dev = dev;
|
|
fw->cl.rx_callback = response_callback;
|
|
fw->cl.tx_block = true;
|
|
|
|
fw->chan = mbox_request_channel(&fw->cl, 0);
|
|
if (IS_ERR(fw->chan))
|
|
return dev_err_probe(dev, PTR_ERR(fw->chan),
|
|
"Failed to get mbox channel\n");
|
|
|
|
init_completion(&fw->c);
|
|
kref_init(&fw->consumers);
|
|
|
|
platform_set_drvdata(pdev, fw);
|
|
|
|
rpi_firmware_print_firmware_revision(fw);
|
|
rpi_register_hwmon_driver(dev, fw);
|
|
rpi_register_clk_driver(dev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void rpi_firmware_shutdown(struct platform_device *pdev)
|
|
{
|
|
struct rpi_firmware *fw = platform_get_drvdata(pdev);
|
|
|
|
if (!fw)
|
|
return;
|
|
|
|
rpi_firmware_property(fw, RPI_FIRMWARE_NOTIFY_REBOOT, NULL, 0);
|
|
}
|
|
|
|
static int rpi_firmware_remove(struct platform_device *pdev)
|
|
{
|
|
struct rpi_firmware *fw = platform_get_drvdata(pdev);
|
|
|
|
platform_device_unregister(rpi_hwmon);
|
|
rpi_hwmon = NULL;
|
|
platform_device_unregister(rpi_clk);
|
|
rpi_clk = NULL;
|
|
|
|
rpi_firmware_put(fw);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id rpi_firmware_of_match[] = {
|
|
{ .compatible = "raspberrypi,bcm2835-firmware", },
|
|
{},
|
|
};
|
|
MODULE_DEVICE_TABLE(of, rpi_firmware_of_match);
|
|
|
|
struct device_node *rpi_firmware_find_node(void)
|
|
{
|
|
return of_find_matching_node(NULL, rpi_firmware_of_match);
|
|
}
|
|
EXPORT_SYMBOL_GPL(rpi_firmware_find_node);
|
|
|
|
/**
|
|
* rpi_firmware_get - Get pointer to rpi_firmware structure.
|
|
* @firmware_node: Pointer to the firmware Device Tree node.
|
|
*
|
|
* The reference to rpi_firmware has to be released with rpi_firmware_put().
|
|
*
|
|
* Returns NULL is the firmware device is not ready.
|
|
*/
|
|
struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
|
|
{
|
|
struct platform_device *pdev = of_find_device_by_node(firmware_node);
|
|
struct rpi_firmware *fw;
|
|
|
|
if (!pdev)
|
|
return NULL;
|
|
|
|
fw = platform_get_drvdata(pdev);
|
|
if (!fw)
|
|
goto err_put_device;
|
|
|
|
if (!kref_get_unless_zero(&fw->consumers))
|
|
goto err_put_device;
|
|
|
|
put_device(&pdev->dev);
|
|
|
|
return fw;
|
|
|
|
err_put_device:
|
|
put_device(&pdev->dev);
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(rpi_firmware_get);
|
|
|
|
/**
|
|
* devm_rpi_firmware_get - Get pointer to rpi_firmware structure.
|
|
* @firmware_node: Pointer to the firmware Device Tree node.
|
|
*
|
|
* Returns NULL is the firmware device is not ready.
|
|
*/
|
|
struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
|
|
struct device_node *firmware_node)
|
|
{
|
|
struct rpi_firmware *fw;
|
|
|
|
fw = rpi_firmware_get(firmware_node);
|
|
if (!fw)
|
|
return NULL;
|
|
|
|
if (devm_add_action_or_reset(dev, devm_rpi_firmware_put, fw))
|
|
return NULL;
|
|
|
|
return fw;
|
|
}
|
|
EXPORT_SYMBOL_GPL(devm_rpi_firmware_get);
|
|
|
|
static struct platform_driver rpi_firmware_driver = {
|
|
.driver = {
|
|
.name = "raspberrypi-firmware",
|
|
.of_match_table = rpi_firmware_of_match,
|
|
},
|
|
.probe = rpi_firmware_probe,
|
|
.shutdown = rpi_firmware_shutdown,
|
|
.remove = rpi_firmware_remove,
|
|
};
|
|
module_platform_driver(rpi_firmware_driver);
|
|
|
|
MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
|
|
MODULE_DESCRIPTION("Raspberry Pi firmware driver");
|
|
MODULE_LICENSE("GPL v2");
|