Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * TI Keystone DSP remoteproc driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/of_reserved_mem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mfd/syscon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/remoteproc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/reset.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "remoteproc_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK	(SZ_16M - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * struct keystone_rproc_mem - internal memory structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * @cpu_addr: MPU virtual address of the memory region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * @bus_addr: Bus address used to access the memory region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * @dev_addr: Device address of the memory region from DSP view
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * @size: Size of the memory region
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) struct keystone_rproc_mem {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	void __iomem *cpu_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	phys_addr_t bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	u32 dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * struct keystone_rproc - keystone remote processor driver structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * @dev: cached device pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * @rproc: remoteproc device handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * @mem: internal memory regions data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @num_mems: number of internal memory regions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @dev_ctrl: device control regmap handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @reset: reset control handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @boot_offset: boot register offset in @dev_ctrl regmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @irq_ring: irq entry for vring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @irq_fault: irq entry for exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * @kick_gpio: gpio used for virtio kicks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * @workqueue: workqueue for processing virtio interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) struct keystone_rproc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct rproc *rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct keystone_rproc_mem *mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int num_mems;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct regmap *dev_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct reset_control *reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	u32 boot_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	int irq_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int irq_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	int kick_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct work_struct workqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /* Put the DSP processor into reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static void keystone_rproc_dsp_reset(struct keystone_rproc *ksproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	reset_control_assert(ksproc->reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) /* Configure the boot address and boot the DSP processor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static int keystone_rproc_dsp_boot(struct keystone_rproc *ksproc, u32 boot_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (boot_addr & (SZ_1K - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		dev_err(ksproc->dev, "invalid boot address 0x%x, must be aligned on a 1KB boundary\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			boot_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	ret = regmap_write(ksproc->dev_ctrl, ksproc->boot_offset, boot_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		dev_err(ksproc->dev, "regmap_write of boot address failed, status = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	reset_control_deassert(ksproc->reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  * Process the remoteproc exceptions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * The exception reporting on Keystone DSP remote processors is very simple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * compared to the equivalent processors on the OMAP family, it is notified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * through a software-designed specific interrupt source in the IPC interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  * generation register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * This function just invokes the rproc_report_crash to report the exception
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * to the remoteproc driver core, to trigger a recovery.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static irqreturn_t keystone_rproc_exception_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct keystone_rproc *ksproc = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	rproc_report_crash(ksproc->rproc, RPROC_FATAL_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * Main virtqueue message workqueue function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * This function is executed upon scheduling of the keystone remoteproc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * driver's workqueue. The workqueue is scheduled by the vring ISR handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * There is no payload message indicating the virtqueue index as is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * case with mailbox-based implementations on OMAP family. As such, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * handler processes both the Tx and Rx virtqueue indices on every invocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * The rproc_vq_interrupt function can detect if there are new unprocessed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * messages or not (returns IRQ_NONE vs IRQ_HANDLED), but there is no need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * to check for these return values. The index 0 triggering will process all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  * pending Rx buffers, and the index 1 triggering will process all newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * available Tx buffers and will wakeup any potentially blocked senders.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * NOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * 1. A payload could be added by using some of the source bits in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  *    IPC interrupt generation registers, but this would need additional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *    changes to the overall IPC stack, and currently there are no benefits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  *    of adapting that approach.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * 2. The current logic is based on an inherent design assumption of supporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  *    only 2 vrings, but this can be changed if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static void handle_event(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	struct keystone_rproc *ksproc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		container_of(work, struct keystone_rproc, workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	rproc_vq_interrupt(ksproc->rproc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	rproc_vq_interrupt(ksproc->rproc, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * Interrupt handler for processing vring kicks from remote processor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static irqreturn_t keystone_rproc_vring_interrupt(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct keystone_rproc *ksproc = dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	schedule_work(&ksproc->workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * Power up the DSP remote processor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * This function will be invoked only after the firmware for this rproc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * was loaded, parsed successfully, and all of its resource requirements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * were met.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int keystone_rproc_start(struct rproc *rproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct keystone_rproc *ksproc = rproc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	INIT_WORK(&ksproc->workqueue, handle_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	ret = request_irq(ksproc->irq_ring, keystone_rproc_vring_interrupt, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			  dev_name(ksproc->dev), ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		dev_err(ksproc->dev, "failed to enable vring interrupt, ret = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	ret = request_irq(ksproc->irq_fault, keystone_rproc_exception_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 			  0, dev_name(ksproc->dev), ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		dev_err(ksproc->dev, "failed to enable exception interrupt, ret = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		goto free_vring_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	ret = keystone_rproc_dsp_boot(ksproc, rproc->bootaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		goto free_exc_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) free_exc_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	free_irq(ksproc->irq_fault, ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) free_vring_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	free_irq(ksproc->irq_ring, ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	flush_work(&ksproc->workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * Stop the DSP remote processor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * This function puts the DSP processor into reset, and finishes processing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * of any pending messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static int keystone_rproc_stop(struct rproc *rproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct keystone_rproc *ksproc = rproc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	keystone_rproc_dsp_reset(ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	free_irq(ksproc->irq_fault, ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	free_irq(ksproc->irq_ring, ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	flush_work(&ksproc->workqueue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  * Kick the remote processor to notify about pending unprocessed messages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * The vqid usage is not used and is inconsequential, as the kick is performed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * through a simulated GPIO (a bit in an IPC interrupt-triggering register),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * the remote processor is expected to process both its Tx and Rx virtqueues.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static void keystone_rproc_kick(struct rproc *rproc, int vqid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct keystone_rproc *ksproc = rproc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (WARN_ON(ksproc->kick_gpio < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	gpio_set_value(ksproc->kick_gpio, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * Custom function to translate a DSP device address (internal RAMs only) to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  * kernel virtual address.  The DSPs can access their RAMs at either an internal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * address visible only from a DSP, or at the SoC-level bus address. Both these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * addresses need to be looked through for translation. The translated addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * can be used either by the remoteproc core for loading (when using kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * remoteproc loader), or by any rpmsg bus drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static void *keystone_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct keystone_rproc *ksproc = rproc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	void __iomem *va = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	phys_addr_t bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	u32 dev_addr, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (len == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	for (i = 0; i < ksproc->num_mems; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		bus_addr = ksproc->mem[i].bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		dev_addr = ksproc->mem[i].dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		size = ksproc->mem[i].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		if (da < KEYSTONE_RPROC_LOCAL_ADDRESS_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			/* handle DSP-view addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			if ((da >= dev_addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			    ((da + len) <= (dev_addr + size))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				offset = da - dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				va = ksproc->mem[i].cpu_addr + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			/* handle SoC-view addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			if ((da >= bus_addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			    (da + len) <= (bus_addr + size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 				offset = da - bus_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				va = ksproc->mem[i].cpu_addr + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return (__force void *)va;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static const struct rproc_ops keystone_rproc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.start		= keystone_rproc_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	.stop		= keystone_rproc_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	.kick		= keystone_rproc_kick,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	.da_to_va	= keystone_rproc_da_to_va,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static int keystone_rproc_of_get_memories(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 					  struct keystone_rproc *ksproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	static const char * const mem_names[] = {"l2sram", "l1pram", "l1dram"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	int num_mems = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	num_mems = ARRAY_SIZE(mem_names);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	ksproc->mem = devm_kcalloc(ksproc->dev, num_mems,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 				   sizeof(*ksproc->mem), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	if (!ksproc->mem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	for (i = 0; i < num_mems; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 						   mem_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		ksproc->mem[i].cpu_addr = devm_ioremap_resource(dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		if (IS_ERR(ksproc->mem[i].cpu_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			dev_err(dev, "failed to parse and map %s memory\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 				mem_names[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 			return PTR_ERR(ksproc->mem[i].cpu_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		ksproc->mem[i].bus_addr = res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		ksproc->mem[i].dev_addr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 				res->start & KEYSTONE_RPROC_LOCAL_ADDRESS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		ksproc->mem[i].size = resource_size(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		/* zero out memories to start in a pristine state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		memset((__force void *)ksproc->mem[i].cpu_addr, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		       ksproc->mem[i].size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	ksproc->num_mems = num_mems;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static int keystone_rproc_of_get_dev_syscon(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 					    struct keystone_rproc *ksproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	struct device_node *np = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (!of_property_read_bool(np, "ti,syscon-dev")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		dev_err(dev, "ti,syscon-dev property is absent\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	ksproc->dev_ctrl =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		syscon_regmap_lookup_by_phandle(np, "ti,syscon-dev");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	if (IS_ERR(ksproc->dev_ctrl)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		ret = PTR_ERR(ksproc->dev_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (of_property_read_u32_index(np, "ti,syscon-dev", 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 				       &ksproc->boot_offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		dev_err(dev, "couldn't read the boot register offset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int keystone_rproc_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct keystone_rproc *ksproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	struct rproc *rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	int dsp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	char *fw_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	char *template = "keystone-dsp%d-fw";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	int name_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (!np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		dev_err(dev, "only DT-based devices are supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	dsp_id = of_alias_get_id(np, "rproc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (dsp_id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		dev_warn(dev, "device does not have an alias id\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		return dsp_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	/* construct a custom default fw name - subject to change in future */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	name_len = strlen(template); /* assuming a single digit alias */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	fw_name = devm_kzalloc(dev, name_len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	if (!fw_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	snprintf(fw_name, name_len, template, dsp_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	rproc = rproc_alloc(dev, dev_name(dev), &keystone_rproc_ops, fw_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			    sizeof(*ksproc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (!rproc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	rproc->has_iommu = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	ksproc = rproc->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	ksproc->rproc = rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	ksproc->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	ret = keystone_rproc_of_get_dev_syscon(pdev, ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		goto free_rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	ksproc->reset = devm_reset_control_get_exclusive(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	if (IS_ERR(ksproc->reset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		ret = PTR_ERR(ksproc->reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		goto free_rproc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	/* enable clock for accessing DSP internal memories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	pm_runtime_enable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	ret = pm_runtime_get_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		dev_err(dev, "failed to enable clock, status = %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		pm_runtime_put_noidle(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		goto disable_rpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	ret = keystone_rproc_of_get_memories(pdev, ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		goto disable_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	ksproc->irq_ring = platform_get_irq_byname(pdev, "vring");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (ksproc->irq_ring < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		ret = ksproc->irq_ring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		goto disable_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	ksproc->irq_fault = platform_get_irq_byname(pdev, "exception");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (ksproc->irq_fault < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		ret = ksproc->irq_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		goto disable_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	ksproc->kick_gpio = of_get_named_gpio_flags(np, "kick-gpios", 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (ksproc->kick_gpio < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		ret = ksproc->kick_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		dev_err(dev, "failed to get gpio for virtio kicks, status = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		goto disable_clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (of_reserved_mem_device_init(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		dev_warn(dev, "device does not have specific CMA pool\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	/* ensure the DSP is in reset before loading firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	ret = reset_control_status(ksproc->reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		dev_err(dev, "failed to get reset status, status = %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		goto release_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	} else if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		WARN(1, "device is not in reset\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		keystone_rproc_dsp_reset(ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	ret = rproc_add(rproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		dev_err(dev, "failed to add register device with remoteproc core, status = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		goto release_mem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	platform_set_drvdata(pdev, ksproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) release_mem:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	of_reserved_mem_device_release(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) disable_clk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	pm_runtime_put_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) disable_rpm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	pm_runtime_disable(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) free_rproc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	rproc_free(rproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static int keystone_rproc_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	struct keystone_rproc *ksproc = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	rproc_del(ksproc->rproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	pm_runtime_put_sync(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	pm_runtime_disable(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	rproc_free(ksproc->rproc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	of_reserved_mem_device_release(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static const struct of_device_id keystone_rproc_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	{ .compatible = "ti,k2hk-dsp", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	{ .compatible = "ti,k2l-dsp", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	{ .compatible = "ti,k2e-dsp", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	{ .compatible = "ti,k2g-dsp", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	{ /* sentinel */ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) MODULE_DEVICE_TABLE(of, keystone_rproc_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) static struct platform_driver keystone_rproc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	.probe	= keystone_rproc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	.remove	= keystone_rproc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	.driver	= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		.name = "keystone-rproc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		.of_match_table = keystone_rproc_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) module_platform_driver(keystone_rproc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) MODULE_AUTHOR("Suman Anna <s-anna@ti.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) MODULE_DESCRIPTION("TI Keystone DSP Remoteproc driver");