Add ASoC support for AMD APUs
Subsystems (6)
cover Add ASoC support for AMD APUs
Hi,
This patch set implements support for i2s audio and new AMD GPUs. The i2s codec is fed by a DMA engine on the GPU. To handle this we create an amd gnb (graphics northbridge) bus which we can hang the i2s codec on. Because of this, this patch set covers two
subsystems: drm and alsa. The drm patches add support for the gnb bus and the ACP hw block which provides the DMA engine for the i2s codec. The alsa patches add the ASoC driver for the i2s codec. Since the alsa changes depend on the drm changes in this patch set as well as some other drm changes queued for 4.3, I'd like to take the alsa patches in via the drm tree.
Patch 3 adds the register headers for the ACP block which is a pretty big patch so I've excluded it from email. The entire patch set can be viewed here:
http://cgit.freedesktop.org/~agd5f/linux/log/?h=acp-upstream
Thanks,
Alex
Chunming Zhou (2):
drm/amdgpu: add amd_gnb_bus support
drm/amd: add ACP 2.x register headers
Maruthi Bayyavarapu (1):
drm/amd: add ACP driver support (v4)
Maruthi Srinivas Bayyavarapu (9):
drm/amd: remove amd gnb bus default runtime pm ops drm/amd: modify ACP DMA buffer position update logic (v2) drm/amd: add ACP suspend/resume functionality drm/amd: change ACP SRAM banks used for audio drm/amd: shutdown unused ACP SRAM memory banks drm/amd: remove bitfield usage in ACP IP module
ASoC: AMD: add AMD ASoC ACP-I2S driver (v2)
ASoC: AMD: add suspend/resume for ACP PCM driver
ASoC: AMD: add ACP PCM driver runtime PM
drivers/gpu/drm/Kconfig | 5 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/amd/acp/Kconfig | 9 + drivers/gpu/drm/amd/acp/Makefile | 9 + drivers/gpu/drm/amd/acp/acp_hw.c | 1134 ++++++++++ drivers/gpu/drm/amd/acp/acp_hw.h | 91 + drivers/gpu/drm/amd/acp/include/acp_gfx_if.h | 49 + drivers/gpu/drm/amd/acp/include/amd_acp.h | 214 ++ drivers/gpu/drm/amd/amdgpu/Makefile | 14 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 11 + drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 201 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h | 40 + drivers/gpu/drm/amd/amdgpu/vi.c | 12 + drivers/gpu/drm/amd/bus/Kconfig | 7 + drivers/gpu/drm/amd/bus/Makefile | 4 + drivers/gpu/drm/amd/bus/amd_gnb_bus.c | 261 +++ drivers/gpu/drm/amd/include/amd_shared.h | 1 + .../gpu/drm/amd/include/asic_reg/acp/acp_2_1_d.h | 437 ++++ .../drm/amd/include/asic_reg/acp/acp_2_1_enum.h | 1198 ++++++++++ .../drm/amd/include/asic_reg/acp/acp_2_1_sh_mask.h | 1568 +++++++++++++ .../gpu/drm/amd/include/asic_reg/acp/acp_2_2_d.h | 609 ++++++ .../drm/amd/include/asic_reg/acp/acp_2_2_enum.h | 1068 +++++++++ .../drm/amd/include/asic_reg/acp/acp_2_2_sh_mask.h | 2292 ++++++++++++++++++++ .../gpu/drm/amd/include/asic_reg/acp/acp_2_3_d.h | 582 +++++ .../drm/amd/include/asic_reg/acp/acp_2_3_enum.h | 1079 +++++++++ .../drm/amd/include/asic_reg/acp/acp_2_3_sh_mask.h | 2192 +++++++++++++++++++ drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h | 78 + sound/soc/Kconfig | 2 +- sound/soc/Makefile | 1 + sound/soc/amd/Kconfig | 13 + sound/soc/amd/Makefile | 11 + sound/soc/amd/acp-pcm-dma.c | 759 +++++++ sound/soc/amd/acp-rt286.c | 264 +++ 33 files changed, 14214 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/amd/acp/Kconfig create mode 100644 drivers/gpu/drm/amd/acp/Makefile create mode 100644 drivers/gpu/drm/amd/acp/acp_hw.c create mode 100644 drivers/gpu/drm/amd/acp/acp_hw.h create mode 100644 drivers/gpu/drm/amd/acp/include/acp_gfx_if.h create mode 100644 drivers/gpu/drm/amd/acp/include/amd_acp.h create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h create mode 100644 drivers/gpu/drm/amd/bus/Kconfig create mode 100644 drivers/gpu/drm/amd/bus/Makefile create mode 100644 drivers/gpu/drm/amd/bus/amd_gnb_bus.c create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_1_d.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_1_enum.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_1_sh_mask.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_2_d.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_2_enum.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_2_sh_mask.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_3_d.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_3_enum.h create mode 100644 drivers/gpu/drm/amd/include/asic_reg/acp/acp_2_3_sh_mask.h create mode 100644 drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h create mode 100644 sound/soc/amd/Kconfig create mode 100644 sound/soc/amd/Makefile create mode 100644 sound/soc/amd/acp-pcm-dma.c create mode 100644 sound/soc/amd/acp-rt286.c
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/12 drm/amdgpu: add amd_gnb_bus support
From: Chunming Zhou <[email protected]>
This is used by the incoming ACP driver. The DMA engine for the i2s audio codec is part of the GPU.
This exposes an amd gnb bus for the i2s codec to
hang off of.
--- drivers/gpu/drm/Kconfig | 3 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/amd/bus/Kconfig | 7 + drivers/gpu/drm/amd/bus/Makefile | 4 + drivers/gpu/drm/amd/bus/amd_gnb_bus.c | 266 ++++++++++++++++++++++++++ drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h | 78 ++++++++ 6 files changed, 359 insertions(+) create mode 100644 drivers/gpu/drm/amd/bus/Kconfig create mode 100644 drivers/gpu/drm/amd/bus/Makefile create mode 100644 drivers/gpu/drm/amd/bus/amd_gnb_bus.c create mode 100644 drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h
drivers/gpu/drm/Kconfig +3 -0
@@ -120,6 +120,8 @@ config DRM_RADEON source "drivers/gpu/drm/radeon/Kconfig" +source "drivers/gpu/drm/amd/bus/Kconfig" + config DRM_AMDGPU tristate "AMD GPU" depends on DRM && PCI
@@ -134,6 +136,7 @@ config DRM_AMDGPU select HWMON select BACKLIGHT_CLASS_DEVICE select INTERVAL_TREE + select DRM_AMD_GNB_BUS help Choose this option if you have a recent AMD Radeon graphics card.
drivers/gpu/drm/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_DRM_TDFX) += tdfx/ obj-$(CONFIG_DRM_R128) += r128/ obj-$(CONFIG_HSA_AMD) += amd/amdkfd/ obj-$(CONFIG_DRM_RADEON)+= radeon/ +obj-$(CONFIG_DRM_AMD_GNB_BUS) += amd/bus/ obj-$(CONFIG_DRM_AMDGPU)+= amd/amdgpu/ obj-$(CONFIG_DRM_MGA) += mga/ obj-$(CONFIG_DRM_I810) += i810/
drivers/gpu/drm/amd/bus/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +menu "AMD GNB BUS" + visible if 0 + +config DRM_AMD_GNB_BUS + tristate "AMD GNB bus - used for GNB IPs such as ACP and ISP" + +endmenu
drivers/gpu/drm/amd/bus/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# +ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amd/include/bus/ + +obj-$(CONFIG_DRM_AMD_GNB_BUS) := amd_gnb_bus.o
drivers/gpu/drm/amd/bus/amd_gnb_bus.c new file +266 -0
266 lines not on this page · raw message
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h new file +78 -0
78 lines not on this page · raw message
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
drivers/gpu/drm/Kconfig config DRM_AMDGPU · line 139
Quoted 5 lines
drivers/gpu/drm/Kconfig +1
-0@@ -134,6 +136,7 @@ config DRM_AMDGPU select HWMON select BACKLIGHT_CLASS_DEVICE select INTERVAL_TREE + select DRM_AMD_GNB_BUS
Here you select the symbol.
[...]
drivers/gpu/drm/amd/bus/Kconfig line 5
Quoted 2 lines
drivers/gpu/drm/amd/bus/Kconfig new file +2
-0+config DRM_AMD_GNB_BUS + tristate "AMD GNB bus - used for GNB IPs such as ACP and ISP"
Here you make it user selectable. Use either or having both doesn't work too well.
Quoted 18 lines
(quoted diff) +2
-0+ +endmenudrivers/gpu/drm/amd/bus/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# +ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amd/include/bus/ + +obj-$(CONFIG_DRM_AMD_GNB_BUS) := amd_gnb_bus.odrivers/gpu/drm/amd/bus/amd_gnb_bus.c new file +0
-0@@ -0,0 +1,266 @@
[..]
Quoted 16 lines
drivers/gpu/drm/amd/bus/amd_gnb_bus.c new file +16
-0+#ifdef CONFIG_PM_SLEEP +static int amd_gnb_bus_legacy_suspend (struct device *dev,pm_message_t mesg) +{ +struct amd_gnb_bus_dev *amd_gnb_bus_dev =to_amd_gnb_bus_device (dev); +struct amd_gnb_bus_driver *driver; + +if (!amd_gnb_bus_dev || !dev->driver) +return 0 ; + driver =to_amd_gnb_bus_driver (dev->driver); +if (!driver->suspend) +return 0 ; +return driver->suspend (amd_gnb_bus_dev, mesg); +} + +static int amd_gnb_bus_legacy_resume (struct device *dev) +{
drivers/gpu/drm/amd/bus/amd_gnb_bus.c line 68
Quoted 10 lines
drivers/gpu/drm/amd/bus/amd_gnb_bus.c new file +10
-0+struct amd_gnb_bus_dev *amd_gnb_bus_dev =to_amd_gnb_bus_device (dev); +struct amd_gnb_bus_driver *driver; + +if (!amd_gnb_bus_dev || !dev->driver) +return 0 ; + driver =to_amd_gnb_bus_driver (dev->driver); +if (!driver->resume) +return 0 ; +return driver->resume (amd_gnb_bus_dev); +}
[...]
Preferably don't add support for legacy suspend/resume to new subsystems. Support for this is supposed to be removed from the kernel. Just use dev_pm_ops and then you can drop all of the above since the PM core does the right thing on its own for dev_pm_ops. No need to have support at the bus level if there is nothing special to do at the bus level.
[...]
Mark Brown
maintainerRe: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
In reply to Alex DeucherQuoted 7 lines · Alex Deucher
From: Chunming Zhou <[email protected]>
This is used by the incoming ACP driver. The DMA engine for the i2s audio codec is part of the GPU.
This exposes an amd gnb bus for the i2s codec to
hang off of.
Could you be more specific about what an "amd gnd bus" is please?
Quoted 4 lines
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h new file +4
-0+enum amd_gnb_bus_ip { +AMD_GNB_IP_ACP_DMA , +AMD_GNB_IP_ACP_I2S , +AMD_GNB_IP_ACP_PCM ,
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h line 43
Quoted 10 lines
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h new file +10
-0+AMD_GNB_IP_ISP , + AMD_GNB_IP_NUM +}; + +struct amd_gnb_bus_dev { +struct device dev;/* generic device interface */ +enum amd_gnb_bus_ip ip; +/* private data can be acp_handle/isp_handle etc.*/ +void *private_data; +};
Looking at the code I'm not seeing too much bus specific except for the above which looks like the sort of device we usually represent as a MFD (with the MFD providing resource distribution and arbitration between various component devices which fit into the subsystem). Why code a new bus for this device?
Re: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
Quoted 10 lines · Mark Brown
Quoted 7 lines · Alex Deucher
From: Chunming Zhou <[email protected]>
This is used by the incoming ACP driver. The DMA engine for the i2s audio codec is part of the GPU.
This exposes an amd gnb bus for the i2s codec to
hang off of.Could you be more specific about what an "amd gnd bus" is please?
It's bus to hang hw blocks of the GPU on that are controlled by other subsystems.
Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h new file +12
-0+enum amd_gnb_bus_ip { +AMD_GNB_IP_ACP_DMA , +AMD_GNB_IP_ACP_I2S , +AMD_GNB_IP_ACP_PCM , +AMD_GNB_IP_ISP , +AMD_GNB_IP_NUM +}; + +struct amd_gnb_bus_dev { +struct device dev;/* generic device interface */ +enum amd_gnb_bus_ip ip; +/* private data can be acp_handle/isp_handle etc.*/
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ void *private_data; +};Looking at the code I'm not seeing too much bus specific except for the above which looks like the sort of device we usually represent as a MFD (with the MFD providing resource distribution and arbitration between various component devices which fit into the subsystem). Why code a new bus for this device?
Adding Felix who did worked on the design for this. The idea is that there are hw blocks on the GPU that are controlled by drivers that are part of other subsystems. Those drivers need access to resources (e.g., the MMIO aperture) controlled by the GPU driver. I guess this is a MFD of sorts. If this is not the preferred way to handle this type of device, what is? Can you point me to another driver that handles this differently?
Alex
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
Hi,
To elaborate more on Alex's explanation ...
AMD SOCs have audio (and in the future potentially also camera image signal processors) IPs built into the GNB (graphics north bridge). These IPs are programmed through MMIO registers in the graphics MMIO aperture. They send events to the host through the graphics IRQ. And they use memory that is accessed through the graphics memory controller. Therefore the GPU driver must be involved in programming these IPs.
However, these functions are not exposed to user mode by the graphics driver subsystem in Linux. Audio is handled by ALSA and camera ISPs are handled by V4L2. We want to represent these IPs as separate devices in the device hierarchy, so that ALSA and V4L2 drivers can discover and bind to them using the standard mechanisms.
Therefore we created this "virtual" GNB bus that allows us to create devices in a sensible place in the device hierarchy, as child devices of the GNB. The enum amd_gnb_bus_ip serves as device ID on this bus. The struct amd_gnb_bus_dev represents the device. Private_data is specific to the type of device. It contains high-level interfaces for ALSA drivers to talk to the audio IP and V4L2 driver to talk to the ISP IP. Any direct HW access, memory management and IRQ handling is done inside the GPU driver.
Regards,
Felix
Quoted 41 lines · Alex Deucher
Quoted 9 lines · Mark Brown
Quoted 7 lines · Alex Deucher
From: Chunming Zhou <[email protected]>
This is used by the incoming ACP driver. The DMA engine for the i2s audio codec is part of the GPU.
This exposes an amd gnb bus for the i2s codec to
hang off of.Could you be more specific about what an "amd gnd bus" is please?
It's bus to hang hw blocks of the GPU on that are controlled by other subsystems.
Quoted 11 lines
Quoted 11 lines
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h new file +11
-0+enum amd_gnb_bus_ip { +AMD_GNB_IP_ACP_DMA , +AMD_GNB_IP_ACP_I2S , +AMD_GNB_IP_ACP_PCM , +AMD_GNB_IP_ISP , +AMD_GNB_IP_NUM +}; + +struct amd_gnb_bus_dev { +struct device dev;/* generic device interface */ +enum amd_gnb_bus_ip ip;Quoted 8 lines
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h line 43
Quoted 3 lines
drivers/gpu/drm/amd/include/bus/amd_gnb_bus.h new file +3
-0+/* private data can be acp_handle/isp_handle etc.*/ +void *private_data; +};Looking at the code I'm not seeing too much bus specific except for the above which looks like the sort of device we usually represent as a MFD (with the MFD providing resource distribution and arbitration between various component devices which fit into the subsystem). Why code a new bus for this device?
Adding Felix who did worked on the design for this. The idea is that there are hw blocks on the GPU that are controlled by drivers that are part of other subsystems. Those drivers need access to resources (e.g., the MMIO aperture) controlled by the GPU driver. I guess this is a MFD of sorts. If this is not the preferred way to handle this type of device, what is? Can you point me to another driver that handles this differently?
Alex
Signature · 13 lines
F e l i x K u e h l i n g SMTS Software Development Engineer | Vertical Workstation/Compute 1 Commerce Valley Dr. East, Markham, ON L3T 7X6 Canada (O) +1(289)695-1597 _ _ _ _____ _____ / \ | \ / | | _ \ \ _ | / A \ | \M/ | | |D) ) /|_| | /_/ \_\ |_| |_| |_____/ |__/ \| facebook.com/AMD | amd.com _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Mark Brown
maintainerRe: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
Quoted 3 lines · Felix Kuehling
Hi,
To elaborate more on Alex's explanation ...
Please don't top post, reply in line deleting any unneeded context so people have context for what's being discussed.
Quoted 3 lines
Therefore we created this "virtual" GNB bus that allows us to create devices in a sensible place in the device hierarchy, as child devices of the GNB. The enum
amd_gnb_bus_ipserves as device ID on this bus. The
Like I say this just sounds like exactly the sort of thing we handle with an MFD, it's a very common pattern.
Re: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
Quoted 2 lines · Mark Brown
Like I say this just sounds like exactly the sort of thing we handle with an MFD, it's a very common pattern.
OK, the MFD documentation in Documentation/devicetree/bindings/mfd/ seemed to imply a dependency on a devicetree. It took me a moment to realize that's just the most common scenario.
In our case we don't have a devicetree, we're talking about a PC platform. The GPU (GNB) is a PCIe device. Does the following sound like proper use of the MFD framework for our case?
1. GPU driver gets initialized, detects a GPU with audio co-processor (ACP)
2. GPU driver registers mfd_cell for the ACP device using mfd_add_hotplug_devices
* It's not really hot-plug, but the mem_base, irq_base, irq_domain parameters don't make sense for us
3. Platform_data in the MFD cell contains audio driver-specific data, function pointers, etc. for the audio driver to use
4. Audio driver binds to platform device created by mfd_add_hotplug_devices based on driver name
Or do we have to convert our GPU device to be an MFD cell itself, a peer of the ACP cell?
Thanks,
Felix
Signature · 8 lines
F e l i x K u e h l i n g SMTS Software Development Engineer | Vertical Workstation/Compute 1 Commerce Valley Dr. East, Markham, ON L3T 7X6 Canada (O) +1(289)695-1597 _ _ _ _____ _____ / \ | \ / | | _ \ \ _ | / A \ | \M/ | | |D) ) /|_| | /_/ \_\ |_| |_| |_____/ |__/ \| facebook.com/AMD | amd.com
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Mark Brown
maintainerRe: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
Quoted 5 lines · Felix Kuehling
1. GPU driver gets initialized, detects a GPU with audio co-processor (ACP)
2. GPU driver registersmfd_cellfor the ACP device usingmfd_add_hotplug_devices
* It's not really hot-plug, but themem_base,irq_base,irq_domainparameters don't make sense for us
All those should be optional...
Quoted 2 lines
3.
Platform_datain the MFD cell contains audio driver-specific data, function pointers, etc. for the audio driver to use
Note that a MFD knows that its parent is the core device so it can just look at the driver data of the parent unless things vary per child.
Quoted 5 lines
4. Audio driver binds to platform device created by
mfd_add_hotplug_devicesbased on driver nameOr do we have to convert our GPU device to be an MFD cell itself, a peer of the ACP cell?
If they're all part of the same block of hardware that'd be more normal, but it all depends on what the code looks like and what the relevant maintainers think.
Mark Brown
maintainerRe: [PATCH 01/12] drm/amdgpu: add amd_gnb_bus support
In reply to Alex DeucherQuoted 8 lines · Alex Deucher
Quoted 5 lines · Mark Brown
Looking at the code I'm not seeing too much bus specific except for the above which looks like the sort of device we usually represent as a MFD (with the MFD providing resource distribution and arbitration between various component devices which fit into the subsystem). Why code a new bus for this device?
Quoted 7 lines
Adding Felix who did worked on the design for this. The idea is that there are hw blocks on the GPU that are controlled by drivers that are part of other subsystems. Those drivers need access to resources (e.g., the MMIO aperture) controlled by the GPU driver. I guess this is a MFD of sorts. If this is not the preferred way to handle this type of device, what is? Can you point me to another driver that handles this differently?
Yeah, this sounds like a MFD - see drivers/mfd and take a look at how the drivers there deal with this.
PATCH 2/12 drm/amd: remove amd gnb bus default runtime pm ops
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
with the default gnb bus runtime pm ops, alsa pcm device attached to it is unable to get runtime suspended/resumed.
--- drivers/gpu/drm/amd/bus/amd_gnb_bus.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/gpu/drm/amd/bus/amd_gnb_bus.c +0 -5
@@ -142,11 +142,6 @@ static const struct dev_pm_ops amd_gnb_bus_device_pm_ops = { .thaw = amd_gnb_bus_device_pm_thaw, .poweroff = amd_gnb_bus_device_pm_poweroff, .restore = amd_gnb_bus_device_pm_restore, -SET_RUNTIME_PM_OPS ( - pm_generic_runtime_suspend, - pm_generic_runtime_resume, - pm_runtime_idle - ) };/* The bus should only be registered by the first amd_gnb, but further
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/12 drm/amd: add ACP driver support (v4)
In reply to Alex DeucherFrom: Maruthi Bayyavarapu <[email protected]>
This adds the ACP (Audio CoProcessor) IP driver and wires it up to the amdgpu driver. The ACP block provides the DMA engine and bus for the i2s codec which is supported by an alsa driver. This is required for audio on APUs that utilize an i2s codec.
v2: integrate i2s/az check patch
v3: s/amd_acp/amdgpu_acp/
v4: update copyright notice
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/amd/acp/Kconfig | 9 + drivers/gpu/drm/amd/acp/Makefile | 9 + drivers/gpu/drm/amd/acp/acp_hw.c | 964 +++++++++++++++++++++++++++ drivers/gpu/drm/amd/acp/acp_hw.h | 99 +++ drivers/gpu/drm/amd/acp/include/acp_gfx_if.h | 49 ++ drivers/gpu/drm/amd/acp/include/amd_acp.h | 196 ++++++ drivers/gpu/drm/amd/amdgpu/Makefile | 14 +- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 11 + drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 201 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h | 40 ++ drivers/gpu/drm/amd/amdgpu/vi.c | 12 + drivers/gpu/drm/amd/include/amd_shared.h | 1 + 13 files changed, 1606 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/acp/Kconfig create mode 100644 drivers/gpu/drm/amd/acp/Makefile create mode 100644 drivers/gpu/drm/amd/acp/acp_hw.c create mode 100644 drivers/gpu/drm/amd/acp/acp_hw.h create mode 100644 drivers/gpu/drm/amd/acp/include/acp_gfx_if.h create mode 100644 drivers/gpu/drm/amd/acp/include/amd_acp.h create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h
drivers/gpu/drm/Kconfig +2 -0
@@ -144,6 +144,8 @@ config DRM_AMDGPU source "drivers/gpu/drm/amd/amdgpu/Kconfig" +source "drivers/gpu/drm/amd/acp/Kconfig" + source "drivers/gpu/drm/nouveau/Kconfig" config DRM_I810
drivers/gpu/drm/amd/acp/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +menu "ACP Configuration" + +config DRM_AMD_ACP + bool "Enable ACP IP support" + default y + help + Choose this option to enable ACP IP support for AMD SOCs. + +endmenu
drivers/gpu/drm/amd/acp/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# +# Makefile for the ACP, which is a sub-component +# of AMDSOC/AMDGPU drm driver. +# It provides the HW control for ACP related functionalities. + +ccflags-y += -Idrivers/gpu/drm/amd/include/asic_reg/acp +subdir-ccflags-y += -I$(AMDACPPATH)/ -I$(AMDACPPATH)/include + +AMD_ACP_FILES := $(AMDACPPATH)/acp_hw.o
drivers/gpu/drm/amd/acp/acp_hw.c new file +964 -0
964 lines not on this page · raw message
drivers/gpu/drm/amd/acp/acp_hw.h new file +99 -0
99 lines not on this page · raw message
drivers/gpu/drm/amd/acp/include/acp_gfx_if.h new file +49 -0
49 lines not on this page · raw message
drivers/gpu/drm/amd/acp/include/amd_acp.h new file +196 -0
196 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/Makefile +13 -1
@@ -3,7 +3,9 @@ # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amd/include/asic_reg \ - -Idrivers/gpu/drm/amd/include + -Idrivers/gpu/drm/amd/include \ + -Idrivers/gpu/drm/amd/include/bus \ + -Idrivers/gpu/drm/amd/acp/include amdgpu-y := amdgpu_drv.o
@@ -80,6 +82,16 @@ amdgpu-y += \ # add cgs amdgpu-y += amdgpu_cgs.o +# ACP componet +ifneq ($(CONFIG_DRM_AMD_ACP),) +amdgpu-y += amdgpu_acp.o + +AMDACPPATH := ../acp +include drivers/gpu/drm/amd/acp/Makefile + +amdgpu-y += $(AMD_ACP_FILES) +endif + amdgpu-$(CONFIG_COMPAT) += amdgpu_ioc32.o amdgpu-$(CONFIG_VGA_SWITCHEROO) += amdgpu_atpx_handler.o amdgpu-$(CONFIG_ACPI) += amdgpu_acpi.o
drivers/gpu/drm/amd/amdgpu/amdgpu.h +11 -0
@@ -53,6 +53,7 @@#include "amdgpu_irq.h" #include "amdgpu_ucode.h" #include "amdgpu_gds.h" +#include "amdgpu_acp.h" /* * Modules parameters.
@@ -1853,6 +1854,12 @@ int amdgpu_ctx_put(struct amdgpu_ctx *ctx);extern int amdgpu_ctx_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +/* +* CGS +*/ +void *amdgpu_cgs_create_device (struct amdgpu_device *adev); +void amdgpu_cgs_destroy_device (void *cgs_device); +/* * Core structure, functions and helpers.
@@ -1869,6 +1876,10 @@ struct amdgpu_device {struct pci_dev *pdev;struct rw_semaphore exclusive_lock; +#ifdef CONFIG_DRM_AMD_ACP +struct amdgpu_acp acp; +#endif +/* ASIC */ enum amdgpu_asic_type asic_type;uint32_t family;
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c new file +201 -0
201 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright 2015 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#ifndef __AMDGPU_ACP_H__ +#define __AMDGPU_ACP_H__ + +#include "amd_gnb_bus.h" + +struct amdgpu_acp { +struct device *parent; +struct amd_gnb_bus_dev acp_pcm_dev; +void *cgs_device; +struct amd_acp_private *private; +}; + +extern const struct amd_ip_funcs acp_ip_funcs; + +#endif /* __AMDGPU_ACP_H__ */
drivers/gpu/drm/amd/amdgpu/vi.c +12 -0
@@ -71,6 +71,9 @@#include "uvd_v5_0.h" #include "uvd_v6_0.h" #include "vce_v3_0.h" +#if defined(CONFIG_DRM_AMD_ACP ) +#include "amdgpu_acp.h" +#endif /* * Indirect registers accessor
@@ -1193,6 +1196,15 @@ static const struct amdgpu_ip_block_version cz_ip_blocks[] = .rev = 0, .funcs = &vce_v3_0_ip_funcs, }, +#if defined(CONFIG_DRM_AMD_ACP ) + { + .type = AMD_IP_BLOCK_TYPE_ACP, + .major = 2, + .minor = 2, + .rev = 0, + .funcs = &acp_ip_funcs, + }, +#endif };int vi_set_ip_blocks (struct amdgpu_device *adev)
drivers/gpu/drm/amd/include/amd_shared.h +1 -0
@@ -33,6 +33,7 @@ enum amd_ip_block_type {AMD_IP_BLOCK_TYPE_SDMA ,AMD_IP_BLOCK_TYPE_UVD ,AMD_IP_BLOCK_TYPE_VCE , + AMD_IP_BLOCK_TYPE_ACP, }; enum amd_clockgating_state {
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/12 drm/amd: modify ACP DMA buffer position update logic (v2)
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
The following are design changes for ACP DMA :
1. For capture usecase, DMA Interrupt on Complete is added for ACP_TO_SYSRAM_CH_NUM DMA channel
2. For playback usecase, the destination for DMA descriptors is reversed.
3. Finally, modified DMA buffer position update logic as per above changes.
v2: minor code cleanups
--- drivers/gpu/drm/amd/acp/acp_hw.c | 156 ++++++++++++++++++++++----------------- drivers/gpu/drm/amd/acp/acp_hw.h | 19 ++--- 2 files changed, 93 insertions(+), 82 deletions(-)
drivers/gpu/drm/amd/acp/acp_hw.c +87 -69
@@ -40,7 +40,7 @@#include <linux/delay.h> #include <linux/errno.h> -#define VISLANDS30_IV_SRCID_ACP 0x000000a2 // 162 +#define VISLANDS30_IV_SRCID_ACP 0x000000a2#include "acp_gfx_if.h" #include "acp_hw.h"
@@ -91,10 +91,9 @@ static void config_acp_dma_channel(struct amd_acp_device *acp_dev, u8 ch_num,/* Initialize the dma descriptors location in SRAM and page size */ -static void acp_dma_descr_init (struct amd_acp_device *acp_dev) +static void acp_dma_descr_init (struct amd_acp_private *acp_prv) {u32 sram_pte_offset =0 ; -struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev;/* SRAM starts at 0x04000000. From that offset one page (4KB) left for * filling DMA descriptors.sram_pte_offset = 0x04001000 , used for
@@ -146,10 +145,11 @@ static void config_dma_descriptor_in_sram(struct amd_acp_device *acp_dev,/* Initialize the DMA descriptor information */ static void set_acp_sysmem_dma_descriptors (struct amd_acp_device *acp_dev, -u32 size,int direction,u32 pte_offset) +u32 size,int direction, +u32 pte_offset) { -u16 dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH12 ;u16 num_descr; +u16 dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH12 ;acp_dma_dscr_transfer_t dmadscr[2 ]; num_descr =2 ;
@@ -157,43 +157,45 @@ static void set_acp_sysmem_dma_descriptors(struct amd_acp_device *acp_dev, dmadscr[0 ].size_xfer_dir.val = (u32 )0x0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH12 ; - dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_38_ADDRESS ; + dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_38_ADDRESS + (size /2 ); dmadscr[0 ].src =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ); dmadscr[0 ].size_xfer_dir.s.trans_direction =ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM ; - }else if (direction ==STREAM_CAPTURE ) { + dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); + dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x0 ; + }else { dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH14 ; dmadscr[0 ].src =ACP_SHARED_RAM_BANK_47_ADDRESS ; dmadscr[0 ].dest =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ); dmadscr[0 ].size_xfer_dir.s.trans_direction =ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION ; + dmadscr[0 ].size_xfer_dir.s.size = size /2 ; + dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ; } -/* allot 1 period size per descriptor = total size (size) /2 -* => params_buffer_bytes(params)/params_periods(params); -*/ - dmadscr[0 ].size_xfer_dir.s.size = size /2 ; - - dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x0 ; -config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[0 ]); dmadscr[1 ].size_xfer_dir.val = (u32 )0x0 ; - dmadscr[1 ].dest = dmadscr[0 ].dest + dmadscr[0 ].size_xfer_dir.s.size; - dmadscr[1 ].src = dmadscr[0 ].src + dmadscr[0 ].size_xfer_dir.s.size; - dmadscr[1 ].size_xfer_dir.s.size = dmadscr[0 ].size_xfer_dir.s.size; - dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x0 ; -if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_END_DMA_DESCR_CH12 ; + dmadscr[1 ].dest =ACP_SHARED_RAM_BANK_38_ADDRESS ; + dmadscr[1 ].src =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + + (pte_offset *PAGE_SIZE_4K ) + (size /2 ); dmadscr[1 ].size_xfer_dir.s.trans_direction =ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM ; - }else if (direction ==STREAM_CAPTURE ) { + dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); + dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x0 ; + }else { dma_dscr_idx =CAPTURE_END_DMA_DESCR_CH14 ; dmadscr[1 ].size_xfer_dir.s.trans_direction =ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION ; + dmadscr[1 ].size_xfer_dir.val = (u32 )0x0 ; + dmadscr[1 ].dest = dmadscr[0 ].dest + (size /2 ); + dmadscr[1 ].src = dmadscr[0 ].src + (size /2 ); + dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); + dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x1 ; }config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[1 ]);
@@ -204,7 +206,7 @@ static void set_acp_sysmem_dma_descriptors(struct amd_acp_device *acp_dev,config_acp_dma_channel (acp_dev,SYSRAM_TO_ACP_CH_NUM , dma_dscr_idx, num_descr,ACP_DMA_PRIORITY_LEVEL_NORMAL ); - }else if (direction ==STREAM_CAPTURE ) { + }else {/* starting descriptor for this channel */ dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH14 ; config_acp_dma_channel(acp_dev, ACP_TO_SYSRAM_CH_NUM,
@@ -228,34 +230,38 @@ static void set_acp_to_i2s_dma_descriptors(struct amd_acp_device *acp_dev,* of data */ dmadscr[0 ].size_xfer_dir.val = (u32 )0x0 ; - dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH13 ; dmadscr[0 ].src =ACP_SHARED_RAM_BANK_38_ADDRESS ; dmadscr[0 ].size_xfer_dir.s.trans_direction =TO_ACP_I2S_1 ; - }else if (direction ==STREAM_CAPTURE ) { + dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); + dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ; + }else { dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH15 ; dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_47_ADDRESS ; - dmadscr[0 ].size_xfer_dir.s.trans_direction =0xa ; + dmadscr[0 ].size_xfer_dir.s.trans_direction =FROM_ACP_I2S_1 ; + dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); + dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ; } +config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[0 ]); dmadscr[1 ].size_xfer_dir.val = (u32 )0x0 ; - dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x1 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_END_DMA_DESCR_CH13 ; - dmadscr[1 ].src = dmadscr[0 ].src + - dmadscr[0 ].size_xfer_dir.s.size; + dmadscr[1 ].src = dmadscr[0 ].src + (size /2 ); dmadscr[1 ].size_xfer_dir.s.trans_direction =TO_ACP_I2S_1 ; + dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); + dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x1 ; - }else if (direction ==STREAM_CAPTURE ) { + }else { dma_dscr_idx =CAPTURE_END_DMA_DESCR_CH15 ; - dmadscr[1 ].dest = dmadscr[0 ].dest + - dmadscr[0 ].size_xfer_dir.s.size; - dmadscr[1 ].size_xfer_dir.s.trans_direction =0xa ; + dmadscr[1 ].dest = dmadscr[0 ].dest + (size /2 ); + dmadscr[1 ].size_xfer_dir.s.trans_direction =FROM_ACP_I2S_1 ; + dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); + dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x1 ; } +config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[1 ]);/* Configure the DMA channel with the above descriptore */
@@ -265,7 +271,7 @@ static void set_acp_to_i2s_dma_descriptors(struct amd_acp_device *acp_dev,config_acp_dma_channel (acp_dev,ACP_TO_I2S_DMA_CH_NUM , dma_dscr_idx, num_descr,ACP_DMA_PRIORITY_LEVEL_NORMAL ); - }else if (direction ==STREAM_CAPTURE ) { + }else {/* starting descriptor for this channel */ dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH15 ; config_acp_dma_channel(acp_dev, I2S_TO_ACP_DMA_CH_NUM,
@@ -284,8 +290,8 @@ static u16 get_dscr_idx(struct amd_acp_device *acp_dev, int direction) dscr_idx =cgs_read_register (acp_prv->cgs_device, mmACP_DMA_CUR_DSCR_13); dscr_idx = (dscr_idx ==PLAYBACK_START_DMA_DESCR_CH13 ) ? -PLAYBACK_END_DMA_DESCR_CH12 : -PLAYBACK_START_DMA_DESCR_CH12 ; +PLAYBACK_START_DMA_DESCR_CH12 : +PLAYBACK_END_DMA_DESCR_CH12 ; }else { dscr_idx =cgs_read_register (acp_prv->cgs_device, mmACP_DMA_CUR_DSCR_15);
@@ -470,7 +476,7 @@ static void configure_i2s_stream(struct amd_acp_device *acp_dev,/*Enable Transmit */ cgs_write_register (acp_prv->cgs_device, (mmACP_I2SSP_TER0 + (0x10 * - i2s_config->ch_reg)),1 ); + i2s_config->ch_reg)),1 ); }else {/* Receive configuration register for data width */ cgs_write_register(acp_prv->cgs_device,
@@ -479,11 +485,11 @@ static void configure_i2s_stream(struct amd_acp_device *acp_dev, i2s_config->xfer_resolution);cgs_write_register (acp_prv->cgs_device, (mmACP_I2SMICSP_RFCR0 + (0x10 * - i2s_config->ch_reg)),0x07 ); + i2s_config->ch_reg)),0x07 );/*Read interrupt mask register */ i2s_config->irq =cgs_read_register (acp_prv->cgs_device, (mmACP_I2SMICSP_IMR0 + - (0x10 * i2s_config->ch_reg))); + (0x10 * i2s_config->ch_reg)));/* TX FIFO Overrun,Empty interrupts */ cgs_write_register(acp_prv->cgs_device,
@@ -493,8 +499,7 @@ static void configure_i2s_stream(struct amd_acp_device *acp_dev,/*Enable Receive */ cgs_write_register (acp_prv->cgs_device, (mmACP_I2SMICSP_RER0 + (0x10 * - i2s_config->ch_reg)),1 ); - + i2s_config->ch_reg)),1 ); } }
@@ -545,16 +550,18 @@ static int acp_dma_start(struct amd_acp_device *acp_dev, dma_ctrl |= ACP_DMA_CNTL_0__DMAChRun_MASK;if ((ch_num ==ACP_TO_I2S_DMA_CH_NUM ) || + (ch_num ==ACP_TO_SYSRAM_CH_NUM ) || (ch_num ==I2S_TO_ACP_DMA_CH_NUM )) { dma_ctrl |= ACP_DMA_CNTL_0__DMAChIOCEn_MASK; -cgs_irq_get (acp_prv->cgs_device,VISLANDS30_IV_SRCID_ACP ,0 ); }else { dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChIOCEn_MASK; }/* enable for ACP SRAM to/from I2S DMA channel */ -if (is_circular == true) +if (is_circular == true) { dma_ctrl |= ACP_DMA_CNTL_0__Circular_DMA_En_MASK; +cgs_irq_get (acp_prv->cgs_device,VISLANDS30_IV_SRCID_ACP ,0 ); + }else dma_ctrl &= ~ACP_DMA_CNTL_0__Circular_DMA_En_MASK;
@@ -562,7 +569,6 @@ static int acp_dma_start(struct amd_acp_device *acp_dev, dma_ctrl); status =STATUS_SUCCESS ; -return status; }
@@ -614,7 +620,8 @@ static int acp_dma_stop(struct amd_acp_device *acp_dev, u8 ch_num) dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRst_MASK;cgs_write_register (acp_prv->cgs_device, - (mmACP_DMA_CNTL_0 + ch_num), dma_ctrl); + (mmACP_DMA_CNTL_0 + ch_num), + dma_ctrl); status =STATUS_SUCCESS ;break ; }
@@ -631,47 +638,58 @@ static int acp_dma_stop(struct amd_acp_device *acp_dev, u8 ch_num)static int dma_irq_handler (void *prv_data) { -u16 play_intr, capture_intr; +u16 play_acp_i2s_intr, cap_i2s_acp_intr, cap_acp_sysram_intr;u16 dscr_idx, intr_flag; +u32 ext_intr_status;int priority_level =0x0 ;int dma_transfer_status =STATUS_UNSUCCESSFUL ;struct acp_irq_prv *idata = prv_data;struct amd_acp_device *acp_dev = idata->acp_dev; +struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev; intr_flag =acp_get_intr_flag (acp_dev); - play_intr = (intr_flag &BIT (ACP_TO_I2S_DMA_CH_NUM )); - capture_intr = (intr_flag &BIT (I2S_TO_ACP_DMA_CH_NUM )); -if (!play_intr && !capture_intr) { + play_acp_i2s_intr = (intr_flag &BIT (ACP_TO_I2S_DMA_CH_NUM )); + cap_i2s_acp_intr = (intr_flag &BIT (I2S_TO_ACP_DMA_CH_NUM )); + cap_acp_sysram_intr = (intr_flag &BIT (ACP_TO_SYSRAM_CH_NUM )); + +if (!play_acp_i2s_intr && !cap_i2s_acp_intr && !cap_acp_sysram_intr) {/* We registered for DMA Interrupt-On-Complete interrupts only. -* If we hit here, just return. */ -pr_info ("ACP:irq_handler: play_intr && capture_intr = false\n" ); +* If we hit here, log, acknowledge it and return. */ + ext_intr_status =cgs_read_register (acp_prv->cgs_device, + mmACP_EXTERNAL_INTR_STAT); +pr_info ("ACP: Not a DMA IOC irq: %x\n" , ext_intr_status);return 0 ; } -if (play_intr) { +if (play_acp_i2s_intr) { dscr_idx =get_dscr_idx (acp_dev,STREAM_PLAYBACK );config_acp_dma_channel (acp_dev,SYSRAM_TO_ACP_CH_NUM , dscr_idx,1 , priority_level); dma_transfer_status =acp_dma_start (acp_dev,SYSRAM_TO_ACP_CH_NUM , false); - idata->set_elapsed (idata->dev, play_intr, capture_intr); + idata->set_elapsed (idata->dev,1 ,0 );acp_ext_stat_clear_dmaioc (acp_dev,ACP_TO_I2S_DMA_CH_NUM ); } -if (capture_intr) { +if (cap_i2s_acp_intr) { dscr_idx =get_dscr_idx (acp_dev,STREAM_CAPTURE );config_acp_dma_channel (acp_dev,ACP_TO_SYSRAM_CH_NUM , dscr_idx,1 , priority_level); dma_transfer_status =acp_dma_start (acp_dev,ACP_TO_SYSRAM_CH_NUM , false); - idata->set_elapsed (idata->dev, play_intr, capture_intr);acp_ext_stat_clear_dmaioc (acp_dev,I2S_TO_ACP_DMA_CH_NUM ); } + +if (cap_acp_sysram_intr) { + idata->set_elapsed (idata->dev,0 ,1 ); +acp_ext_stat_clear_dmaioc (acp_dev,ACP_TO_SYSRAM_CH_NUM ); + } +return 0 ; }
@@ -737,7 +755,7 @@ static int acp_hw_init(struct amd_acp_device *acp_dev, void *iprv)cgs_write_register (acp_prv->cgs_device, mmACP_AXI2DAGB_GARLIC_CNTL,GARLIC_CNTL_DEFAULT ); -acp_dma_descr_init (acp_dev); +acp_dma_descr_init (acp_prv);/* DMA DSCR BASE ADDRESS IN SRAM */ cgs_write_register(acp_prv->cgs_device, mmACP_DMA_DESC_BASE_ADDR,
@@ -811,24 +829,24 @@ static u32 acp_update_dma_pointer(struct amd_acp_device *acp_dev, int direction,if (direction ==STREAM_PLAYBACK ) { dscr =cgs_read_register (acp_prv->cgs_device, mmACP_DMA_CUR_DSCR_13); - pos =cgs_read_register (acp_prv->cgs_device, - mmACP_DMA_CUR_TRANS_CNT_13); -/* dscr = either 2 or 3 only */ - mul = (dscr ==PLAYBACK_START_DMA_DESCR_CH13 ) ?1 :0 ; - pos = (mul * period_size) + pos; - }else if (direction ==STREAM_CAPTURE ) { - dscr =cgs_read_register (acp_prv->cgs_device, - mmACP_DMA_CUR_DSCR_15); - pos =cgs_read_register (acp_prv->cgs_device, - mmACP_DMA_CUR_TRANS_CNT_15); + + mul = (dscr ==PLAYBACK_START_DMA_DESCR_CH13 ) ?0 :1 ; + pos = (mul * period_size); + + }else { dma_config =cgs_read_register (acp_prv->cgs_device, mmACP_DMA_CNTL_14);if (dma_config !=0 ) { - mul = (dscr ==CAPTURE_START_DMA_DESCR_CH15 ) ?1 :0 ; - pos = (mul * period_size) + pos; + dscr =cgs_read_register (acp_prv->cgs_device, + mmACP_DMA_CUR_DSCR_14); + mul = (dscr ==CAPTURE_START_DMA_DESCR_CH14 ) ?1 :2 ; + pos = (mul * period_size); } - } +if (pos >= (2 * period_size)) + pos =0 ; + + }return pos; }
drivers/gpu/drm/amd/acp/acp_hw.h +6 -13
@@ -22,7 +22,7 @@#define ACP_SHARED_RAM_BANK_38_ADDRESS 0x404A000/* Capture SRAM address (as a source in dma descriptor) */ -#define ACP_SHARED_RAM_BANK_47_ADDRESS 0x405C000 +#define ACP_SHARED_RAM_BANK_47_ADDRESS 0x4054000#define ACP_DMA_RESET_TIME 10000#define ACP_CLOCK_EN_TIME_OUT_VALUE 0x000000FF
@@ -35,6 +35,11 @@#define ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS 0x00000000#define ACP_INTERNAL_APERTURE_WINDOW_4_ADDRESS 0x01800000 +#define TO_ACP_I2S_1 0x2 +#define TO_ACP_I2S_2 0x4 +#define FROM_ACP_I2S_1 0xa +#define FROM_ACP_I2S_2 0xb +enum {STREAM_PLAYBACK =0 ,STREAM_CAPTURE ,
@@ -42,18 +47,6 @@ enum { };enum { - To_DAGB_O =0x0 , - To_DAGB_G, -TO_ACP_I2S_1 , -TO_BLUETOOTH , -TO_ACP_I2S_2 , -FROM_DAGB_O , -FROM_DAGB_G , -FROM_ACP_I2S_1 , -FROM_ACP_I2S_2 -}; - -enum {ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION =0x0 ,ACP_DMA_ATTRIBUTES_SHARED_MEM_TO_DAGB_GARLIC =0x1 ,ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM =0x8 ,
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/12 drm/amd: add ACP suspend/resume functionality
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
ACP IP can be powered on and off during system wide suspend/resume transition. AMD ASoC PCM device will use this module during system suspend/resume and PCM device's runtime pm.
Also, updated code comments.
--- drivers/gpu/drm/amd/acp/acp_hw.c | 220 +++++++++++++++++++++++------- drivers/gpu/drm/amd/acp/acp_hw.h | 19 +++ drivers/gpu/drm/amd/acp/include/amd_acp.h | 18 +++ 3 files changed, 204 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/acp/acp_hw.c +167 -53
@@ -40,17 +40,16 @@#include <linux/delay.h> #include <linux/errno.h> -#define VISLANDS30_IV_SRCID_ACP 0x000000a2 -#include "acp_gfx_if.h" #include "acp_hw.h" #include "acp_2_2_d.h" #include "acp_2_2_sh_mask.h" +#define VISLANDS30_IV_SRCID_ACP 0x000000a2 +/* Configure a given dma channel parameters - enable/disble, * number of descriptors, priority */ -static void config_acp_dma_channel (struct amd_acp_device *acp_dev,u8 ch_num,u16 dscr_strt_idx,u16 num_dscrs,enum acp_dma_priority_level priority_level)
@@ -58,38 +57,30 @@ static void config_acp_dma_channel(struct amd_acp_device *acp_dev, u8 ch_num,u32 dma_ctrl;struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev; -/* read the dma control register and disable the channel run field */ +/* disable the channel run field */ dma_ctrl =cgs_read_register (acp_prv->cgs_device, mmACP_DMA_CNTL_0 + ch_num); -/* clear the dma channel control bits */ dma_ctrl &= ~ACP_DMA_CNTL_0__DMAChRun_MASK; -cgs_write_register (acp_prv->cgs_device, (mmACP_DMA_CNTL_0 + ch_num), dma_ctrl); -/* there is no transfer happening on this channel so -* program DMAChDscrStrIdx to the index number of the first descriptor -* to be processed. -*/ +/* program a DMA channel with first descriptor to be processed. */ cgs_write_register (acp_prv->cgs_device, (mmACP_DMA_DSCR_STRT_IDX_0 + ch_num), (ACP_DMA_DSCR_STRT_IDX_0__DMAChDscrStrtIdx_MASK & dscr_strt_idx)); -/* program DMAChDscrDscrCnt to the number of descriptors to be -* processed in the transfer -*/ +/* program a DMA channel with the number of descriptors to be +* processed in the transfer */ cgs_write_register (acp_prv->cgs_device, (mmACP_DMA_DSCR_CNT_0 + ch_num), (ACP_DMA_DSCR_CNT_0__DMAChDscrCnt_MASK & num_dscrs)); -/* set DMAChPrioLvl according to the priority */ +/* set DMA channel priority */ cgs_write_register (acp_prv->cgs_device, (mmACP_DMA_PRIO_0 + ch_num), priority_level); } - -/* Initialize the dma descriptors location in SRAM and page size */ static void acp_dma_descr_init (struct amd_acp_private *acp_prv) {
@@ -143,7 +134,9 @@ static void config_dma_descriptor_in_sram(struct amd_acp_device *acp_dev, descr_info->size_xfer_dir.val); } -/* Initialize the DMA descriptor information */ +/* Initialize the DMA descriptor information for transfer between +* system memory <-> ACP SRAM +*/ static void set_acp_sysmem_dma_descriptors (struct amd_acp_device *acp_dev,u32 size,int direction,u32 pte_offset)
@@ -215,7 +208,9 @@ static void set_acp_sysmem_dma_descriptors(struct amd_acp_device *acp_dev, } } -/* Initialize the i2s dma descriptors in SRAM */ +/* Initialize the DMA descriptor information for transfer between +* ACP SRAM <-> I2S +*/ static void set_acp_to_i2s_dma_descriptors (struct amd_acp_device *acp_dev,u32 size,int direction) {
@@ -226,9 +221,6 @@ static void set_acp_to_i2s_dma_descriptors(struct amd_acp_device *acp_dev, num_descr =2 ; -/* Let I2s Know the direction of transfer and source/destination -* of data -*/ dmadscr[0 ].size_xfer_dir.val = (u32 )0x0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH13 ;
@@ -304,7 +296,7 @@ static u16 get_dscr_idx(struct amd_acp_device *acp_dev, int direction) } -/* Create page table entries in ACP SRAM for the allocated memory */ +/* Create page table entries in ACP SRAM for the allocated memory */ static void acp_pte_config (struct amd_acp_device *acp_dev,struct page *pg,u16 num_of_pages,u32 pte_offset) {
@@ -344,7 +336,6 @@ static void acp_pte_config(struct amd_acp_device *acp_dev, struct page *pg, } } -/* enables/disables ACP's external interrupt */ static void acp_enable_external_interrupts (struct amd_acp_device *acp_dev,int enable)
@@ -361,8 +352,8 @@ static void acp_enable_external_interrupts(struct amd_acp_device *acp_dev, mmACP_EXTERNAL_INTR_ENB, acp_ext_intr_enb); } -/* Clear (acknowledge) DMA 'Interrupt on Complete' (IOC) in ACP -* external interrupt status register +/* Clear (acknowledge) DMA 'Interrupt on Complete' (IOC) in ACP +* external interrupt status register */ static void acp_ext_stat_clear_dmaioc (struct amd_acp_device *acp_dev,u8 ch_num) {
@@ -382,7 +373,7 @@ static void acp_ext_stat_clear_dmaioc(struct amd_acp_device *acp_dev, u8 ch_num) } } -/* Check whether interrupt (IOC) is generated or not */ +/* Check whether ACP DMA interrupt (IOC) is generated or not */ static u16 acp_get_intr_flag (struct amd_acp_device *acp_dev) {u32 ext_intr_status;
@@ -412,7 +403,6 @@ static int irq_set_source(void *private_data, unsigned src_id, unsigned type, } } -static inline void i2s_clear_irqs (struct amd_acp_device *acp_dev,int direction) {
@@ -516,17 +506,17 @@ static void config_acp_dma(struct amd_acp_device *acp_dev,acp_pte_config (acp_dev, dma_config->pg, dma_config->num_of_pages, pte_offset); -/* Configure System memory to acp dma descriptors */ +/* Configure System memory <-> ACP SRAM DMA descriptors */ set_acp_sysmem_dma_descriptors (acp_dev, dma_config->size, dma_config->direction, pte_offset); -/* Configure acp to i2s dma descriptors */ +/* Configure ACP SRAM <-> I2S DMA descriptors */ set_acp_to_i2s_dma_descriptors (acp_dev, dma_config->size, dma_config->direction); } -/* Start a given dma channel */ +/* Start a given DMA channel transfer */ static int acp_dma_start (struct amd_acp_device *acp_dev,u16 ch_num,bool is_circular) {
@@ -572,7 +562,7 @@ static int acp_dma_start(struct amd_acp_device *acp_dev,return status; } -/* Stop a given dma channel number*/ +/* Stop a given DMA channel transfer */ static int acp_dma_stop (struct amd_acp_device *acp_dev,u8 ch_num) {int status =STATUS_UNSUCCESSFUL ;
@@ -584,7 +574,6 @@ static int acp_dma_stop(struct amd_acp_device *acp_dev, u8 ch_num)if (acp_dev ==NULL )return status; -/* register mask value to check the channel status bits */ dma_ctrl =cgs_read_register (acp_prv->cgs_device, mmACP_DMA_CNTL_0 + ch_num);
@@ -636,6 +625,7 @@ static int acp_dma_stop(struct amd_acp_device *acp_dev, u8 ch_num)return status; } +/* ACP DMA irq handler routine for playback, capture usecases */ static int dma_irq_handler (void *prv_data) {u16 play_acp_i2s_intr, cap_i2s_acp_intr, cap_acp_sysram_intr;
@@ -655,7 +645,7 @@ static int dma_irq_handler(void *prv_data)if (!play_acp_i2s_intr && !cap_i2s_acp_intr && !cap_acp_sysram_intr) {/* We registered for DMA Interrupt-On-Complete interrupts only. -* If we hit here, log, acknowledge it and return. */ +* If we hit here, log it and return. */ ext_intr_status =cgs_read_register (acp_prv->cgs_device, mmACP_EXTERNAL_INTR_STAT);pr_info ("ACP: Not a DMA IOC irq: %x\n" , ext_intr_status);
@@ -702,16 +692,92 @@ static int irq_handler(void *private_data, unsigned src_id,return -1 ; } +/* power off a tile/block within ACP */ +static void acp_suspend_tile (struct amd_acp_private *acp_prv,int tile) +{ +u32 val =0 ; +u32 timeout =0 ; + +if ((tile <ACP_TILE_P1 ) || (tile >ACP_TILE_DSP2 )) { +pr_err (" %s : Invalid ACP power tile index\n" , __func__); +return ; + } + + val =cgs_read_register (acp_prv->cgs_device, + mmACP_PGFSM_READ_REG_0 + tile); + val &=ACP_TILE_ON_MASK ; + +if (val ==0x0 ) { + val =cgs_read_register (acp_prv->cgs_device, + mmACP_PGFSM_RETAIN_REG); + val = val | (1 << tile); +cgs_write_register (acp_prv->cgs_device, mmACP_PGFSM_RETAIN_REG, + val); +cgs_write_register (acp_prv->cgs_device, mmACP_PGFSM_CONFIG_REG, +0x500 + tile); + + timeout =ACP_SOFT_RESET_DONE_TIME_OUT_VALUE ; +while (timeout--) { + val =cgs_read_register (acp_prv->cgs_device, + mmACP_PGFSM_READ_REG_0 + tile); + val = val &ACP_TILE_ON_MASK ; +if (val ==ACP_TILE_OFF_MASK ) +break ; + } + + val =cgs_read_register (acp_prv->cgs_device, + mmACP_PGFSM_RETAIN_REG); + + val |=ACP_TILE_OFF_RETAIN_REG_MASK ; +cgs_write_register (acp_prv->cgs_device, mmACP_PGFSM_RETAIN_REG, + val); + } + +} + +/* power on a tile/block within ACP */ +static void acp_resume_tile (struct amd_acp_private *acp_prv,int tile) +{ +u32 val =0 ; +u32 timeout =0 ; + +if ((tile <ACP_TILE_P1 ) || (tile >ACP_TILE_DSP2 )) { +pr_err (" %s : Invalid ACP power tile index\n" , __func__); +return ; + } + + val =cgs_read_register (acp_prv->cgs_device, + mmACP_PGFSM_READ_REG_0 + tile); + val = val &ACP_TILE_ON_MASK ; + +if (val !=0x0 ) { +cgs_write_register (acp_prv->cgs_device, mmACP_PGFSM_CONFIG_REG, +0x600 + tile); + timeout =ACP_SOFT_RESET_DONE_TIME_OUT_VALUE ; +while (timeout--) { + val =cgs_read_register (acp_prv->cgs_device, + mmACP_PGFSM_READ_REG_0 + tile); + val = val &ACP_TILE_ON_MASK ; +if (val ==0x0 ) +break ; + } + val =cgs_read_register (acp_prv->cgs_device, + mmACP_PGFSM_RETAIN_REG); +if (tile ==ACP_TILE_P1 ) + val = val & (ACP_TILE_P1_MASK ); +else if (tile ==ACP_TILE_P2 ) + val = val & (ACP_TILE_P2_MASK ); + +cgs_write_register (acp_prv->cgs_device, mmACP_PGFSM_RETAIN_REG, + val); + } +} +/* Initialize and bring ACP hardware to default state. */ -static int acp_hw_init (struct amd_acp_device *acp_dev,void *iprv) +static void acp_init (struct amd_acp_private *acp_prv) {u32 val;u32 timeout_value; -int acp_hw_init_status =STATUS_UNSUCCESSFUL ; -struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev; - -if (acp_dev ==NULL ) -return acp_hw_init_status;/* Assert Soft reset of ACP */ val =cgs_read_register (acp_prv->cgs_device, mmACP_SOFT_RESET);
@@ -728,7 +794,7 @@ static int acp_hw_init(struct amd_acp_device *acp_dev, void *iprv)break ; } -/* Enabling clock to ACP and waits until the clock is enabled */ +/* Enable clock to ACP and wait until the clock is enabled */ val =cgs_read_register (acp_prv->cgs_device, mmACP_CONTROL); val = val | ACP_CONTROL__ClkEn_MASK;cgs_write_register (acp_prv->cgs_device, mmACP_CONTROL, val);
@@ -757,7 +823,6 @@ static int acp_hw_init(struct amd_acp_device *acp_dev, void *iprv)acp_dma_descr_init (acp_prv); -/* DMA DSCR BASE ADDRESS IN SRAM */ cgs_write_register (acp_prv->cgs_device, mmACP_DMA_DESC_BASE_ADDR,ACP_SRAM_BASE_ADDRESS );
@@ -768,20 +833,34 @@ static int acp_hw_init(struct amd_acp_device *acp_dev, void *iprv)cgs_write_register (acp_prv->cgs_device, mmACP_EXTERNAL_INTR_CNTL, ACP_EXTERNAL_INTR_CNTL__DMAIOCMask_MASK); +pr_info ("ACP: Initialized.\n" ); + +} + +static int acp_hw_init (struct amd_acp_device *acp_dev,void *iprv) +{ +struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev; + +acp_init (acp_prv); +cgs_add_irq_source (acp_prv->cgs_device,VISLANDS30_IV_SRCID_ACP ,1 , - irq_set_source, irq_handler, iprv); + irq_set_source, irq_handler, iprv); + +/* Disable DSPs which are not used */ +acp_suspend_tile (acp_prv,ACP_TILE_DSP0 ); +acp_suspend_tile (acp_prv,ACP_TILE_DSP1 ); +acp_suspend_tile (acp_prv,ACP_TILE_DSP2 ); -pr_info ("ACP: Initialized.\n" );return STATUS_SUCCESS ; } -static void acp_hw_deinit (struct amd_acp_device *acp_dev) +/* Deintialize ACP */ +static void acp_deinit (struct amd_acp_private *acp_prv) {u32 val;u32 timeout_value; -struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev; -/* Assert Soft reset of ACP */ +/* Assert Soft reset of ACP */ val =cgs_read_register (acp_prv->cgs_device, mmACP_SOFT_RESET); val |= ACP_SOFT_RESET__SoftResetAud_MASK;
@@ -795,7 +874,7 @@ static void acp_hw_deinit(struct amd_acp_device *acp_dev)break ; } } -/** Disable ACP clock */ +/** Disable ACP clock */ val =cgs_read_register (acp_prv->cgs_device, mmACP_CONTROL); val &= ~ACP_CONTROL__ClkEn_MASK;cgs_write_register (acp_prv->cgs_device, mmACP_CONTROL, val);
@@ -812,9 +891,15 @@ static void acp_hw_deinit(struct amd_acp_device *acp_dev)pr_info ("ACP: De-Initialized.\n" ); } +static void acp_hw_deinit (struct amd_acp_device *acp_dev) +{ +struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev; + +acp_deinit (acp_prv); +} -/* Get the number of bytes consumed for SRAM_TO_I2S DMA -* channel during rendering +/* Update DMA postion in audio ring buffer at period level granularity. +* This will be used by ALSA PCM driver */ static u32 acp_update_dma_pointer (struct amd_acp_device *acp_dev,int direction,u32 period_size)
@@ -824,6 +909,7 @@ static u32 acp_update_dma_pointer(struct amd_acp_device *acp_dev, int direction,u32 mul;u32 dma_config;struct amd_acp_private *acp_prv = (struct amd_acp_private *)acp_dev; + pos =0 ;if (direction ==STREAM_PLAYBACK ) {
@@ -850,8 +936,8 @@ static u32 acp_update_dma_pointer(struct amd_acp_device *acp_dev, int direction,return pos; } -/* Wait for complete buffering to complete in HOST -* to SRAM DMA channel +/* Wait for initial buffering to complete in HOST to SRAM DMA channel +* for plaback usecase */ static void wait_for_prebuffer_finish (struct amd_acp_device *acp_dev) {
@@ -927,6 +1013,22 @@ static void configure_i2s(struct amd_acp_device *acp_dev,configure_i2s_stream (acp_dev, i2s_config); } +void amd_acp_pcm_suspend (struct amd_acp_device *acp_dev) +{ +struct amd_acp_private *acp_prv; + + acp_prv = (struct amd_acp_private *)acp_dev; +amd_acp_suspend (acp_prv); +} + +void amd_acp_pcm_resume (struct amd_acp_device *acp_dev) +{ +struct amd_acp_private *acp_prv; + + acp_prv = (struct amd_acp_private *)acp_dev; +amd_acp_resume (acp_prv); +} +int amd_acp_hw_init (void *cgs_device,unsigned acp_version_major,unsigned acp_version_minor,struct amd_acp_private **acp_private)
@@ -962,6 +1064,9 @@ int amd_acp_hw_init(void *cgs_device, (*acp_private)->public.i2s_start = i2s_start; (*acp_private)->public.i2s_stop = i2s_stop; + (*acp_private)->public.acp_suspend = amd_acp_pcm_suspend; + (*acp_private)->public.acp_resume = amd_acp_pcm_resume; +return 0 ; }
@@ -973,10 +1078,19 @@ int amd_acp_hw_fini(struct amd_acp_private *acp_private)void amd_acp_suspend (struct amd_acp_private *acp_private) { -/* TODO */ +acp_suspend_tile (acp_private,ACP_TILE_P2 ); +acp_suspend_tile (acp_private,ACP_TILE_P1 ); }void amd_acp_resume (struct amd_acp_private *acp_private) { -/* TODO */ +acp_resume_tile (acp_private,ACP_TILE_P1 ); +acp_resume_tile (acp_private,ACP_TILE_P2 ); + +acp_init (acp_private); + +/* Disable DSPs which are not going to be used */ +acp_suspend_tile (acp_private,ACP_TILE_DSP0 ); +acp_suspend_tile (acp_private,ACP_TILE_DSP1 ); +acp_suspend_tile (acp_private,ACP_TILE_DSP2 ); }
drivers/gpu/drm/amd/acp/acp_hw.h +19 -0
@@ -40,6 +40,25 @@#define FROM_ACP_I2S_1 0xa#define FROM_ACP_I2S_2 0xb +#define ACP_TILE_ON_MASK 0x03 +#define ACP_TILE_OFF_MASK 0x02 +#define ACP_TILE_ON_RETAIN_REG_MASK 0x1f +#define ACP_TILE_OFF_RETAIN_REG_MASK 0x20 + +#define ACP_TILE_P1_MASK 0x3e +#define ACP_TILE_P2_MASK 0x3d +#define ACP_TILE_DSP0_MASK 0x3b +#define ACP_TILE_DSP1_MASK 0x37 +#define ACP_TILE_DSP2_MASK 0x2f + +enum { +ACP_TILE_P1 =0 , +ACP_TILE_P2 , +ACP_TILE_DSP0 , +ACP_TILE_DSP1 , +ACP_TILE_DSP2 , +}; +enum {STREAM_PLAYBACK =0 ,STREAM_CAPTURE ,
drivers/gpu/drm/amd/acp/include/amd_acp.h +18 -0
@@ -189,8 +189,26 @@ struct amd_acp_device {*/ void (*i2s_stop)(struct amd_acp_device *acp_dev,int direction); +/** +* acp_suspend() - Power off ACP +* @acp_dev: acp device +* +* Switch off power tiles of ACP +*/ +void (*acp_suspend)(struct amd_acp_device *acp_dev); + +/** +* acp_resume() - Power on ACP +* @acp_dev: acp device +* +* Switch on power tiles of ACP +*/ + +void (*acp_resume)(struct amd_acp_device *acp_dev); +/* TODO: Need callback registration interface for asynchronous * notifications */ + };#endif /* _AMD_ACP_H */
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 7/12 drm/amd: change ACP SRAM banks used for audio
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
There are 48 SRAM memory banks in ACP 2.1. Use bank index - 0 for DMA descriptors 1 to 4 for playback, 5 to 8 for capture.
--- drivers/gpu/drm/amd/acp/acp_hw.c | 10 +++++----- drivers/gpu/drm/amd/acp/acp_hw.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/acp/acp_hw.c +5 -5
@@ -150,7 +150,7 @@ static void set_acp_sysmem_dma_descriptors(struct amd_acp_device *acp_dev, dmadscr[0 ].size_xfer_dir.val = (u32 )0x0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH12 ; - dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_38_ADDRESS + (size /2 ); + dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_1_ADDRESS + (size /2 ); dmadscr[0 ].src =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ); dmadscr[0].size_xfer_dir.s.trans_direction =
@@ -159,7 +159,7 @@ static void set_acp_sysmem_dma_descriptors(struct amd_acp_device *acp_dev, dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x0 ; }else { dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH14 ; - dmadscr[0 ].src =ACP_SHARED_RAM_BANK_47_ADDRESS ; + dmadscr[0 ].src =ACP_SHARED_RAM_BANK_5_ADDRESS ; dmadscr[0 ].dest =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ); dmadscr[0].size_xfer_dir.s.trans_direction =
@@ -173,7 +173,7 @@ static void set_acp_sysmem_dma_descriptors(struct amd_acp_device *acp_dev, dmadscr[1 ].size_xfer_dir.val = (u32 )0x0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_END_DMA_DESCR_CH12 ; - dmadscr[1 ].dest =ACP_SHARED_RAM_BANK_38_ADDRESS ; + dmadscr[1 ].dest =ACP_SHARED_RAM_BANK_1_ADDRESS ; dmadscr[1 ].src =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ) + (size /2 ); dmadscr[1].size_xfer_dir.s.trans_direction =
@@ -224,13 +224,13 @@ static void set_acp_to_i2s_dma_descriptors(struct amd_acp_device *acp_dev, dmadscr[0 ].size_xfer_dir.val = (u32 )0x0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH13 ; - dmadscr[0 ].src =ACP_SHARED_RAM_BANK_38_ADDRESS ; + dmadscr[0 ].src =ACP_SHARED_RAM_BANK_1_ADDRESS ; dmadscr[0 ].size_xfer_dir.s.trans_direction =TO_ACP_I2S_1 ; dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ; }else { dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH15 ; - dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_47_ADDRESS ; + dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_5_ADDRESS ; dmadscr[0 ].size_xfer_dir.s.trans_direction =FROM_ACP_I2S_1 ; dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ;
drivers/gpu/drm/amd/acp/acp_hw.h +2 -2
@@ -19,10 +19,10 @@#define ACP_PHYSICAL_BASE 0x14000/* Playback SRAM address (as a destination in dma descriptor) */ -#define ACP_SHARED_RAM_BANK_38_ADDRESS 0x404A000 +#define ACP_SHARED_RAM_BANK_1_ADDRESS 0x4002000/* Capture SRAM address (as a source in dma descriptor) */ -#define ACP_SHARED_RAM_BANK_47_ADDRESS 0x4054000 +#define ACP_SHARED_RAM_BANK_5_ADDRESS 0x400A000#define ACP_DMA_RESET_TIME 10000#define ACP_CLOCK_EN_TIME_OUT_VALUE 0x000000FF
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 8/12 drm/amd: shutdown unused ACP SRAM memory banks
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
ACP internal memory banks 0 to 9 are used for audio usecases (playback/capture). Remaining banks 10 to 47 are shutdown to save power.
--- drivers/gpu/drm/amd/acp/acp_hw.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/gpu/drm/amd/acp/acp_hw.c +47 -0
@@ -773,6 +773,52 @@ static void acp_resume_tile(struct amd_acp_private *acp_prv, int tile) } } +/* Shutdown unused SRAM memory banks in ACP IP */ +static void acp_turnoff_sram_banks (struct amd_acp_private *acp_prv) +{ +/* Bank 0 : used for DMA descriptors +* Bank 1 to 4 : used for playback +* Bank 5 to 8 : used for capture +* Each bank is 8kB and max size allocated for playback/ capture is +* 16kB(max period size) * 2(max periods) reserved for playback/capture +* in ALSA driver +* Turn off all SRAM banks except above banks during playback/capture +*/ +u32 val, bank; + +for (bank =9 ; bank <32 ; bank++) { + val =cgs_read_register (acp_prv->cgs_device, + mmACP_MEM_SHUT_DOWN_REQ_LO); +if (!(val & (1 << bank))) { + val |=1 << bank; +cgs_write_register (acp_prv->cgs_device, + mmACP_MEM_SHUT_DOWN_REQ_LO, val); +/* If ACP_MEM_SHUT_DOWN_STS_LO is 0xFFFFFFFF, then +* shutdown sequence is complete. */ +do { + val =cgs_read_register (acp_prv->cgs_device, + mmACP_MEM_SHUT_DOWN_STS_LO); + }while (val !=0xFFFFFFFF ); + } + } + +for (bank =32 ; bank <48 ; bank++) { + val =cgs_read_register (acp_prv->cgs_device, + mmACP_MEM_SHUT_DOWN_REQ_HI); +if (!(val & (1 << (bank -32 )))) { + val |=1 << (bank -32 ); +cgs_write_register (acp_prv->cgs_device, + mmACP_MEM_SHUT_DOWN_REQ_HI, val); +/* If ACP_MEM_SHUT_DOWN_STS_HI is 0x0000FFFF, then +* shutdown sequence is complete. */ +do { + val =cgs_read_register (acp_prv->cgs_device, + mmACP_MEM_SHUT_DOWN_STS_HI); + }while (val !=0x0000FFFF ); + } + } +} +/* Initialize and bring ACP hardware to default state. */ static void acp_init (struct amd_acp_private *acp_prv) {
@@ -833,6 +879,7 @@ static void acp_init(struct amd_acp_private *acp_prv)cgs_write_register (acp_prv->cgs_device, mmACP_EXTERNAL_INTR_CNTL, ACP_EXTERNAL_INTR_CNTL__DMAIOCMask_MASK); +acp_turnoff_sram_banks (acp_prv);pr_info ("ACP: Initialized.\n" ); }
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 9/12 drm/amd: remove bitfield usage in ACP IP module
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
Replaced usage of bitfield logic with alternative
Reviewed- by: Alex Deucher <[email protected]>
--- drivers/gpu/drm/amd/acp/acp_hw.c | 61 +++++++++++++++++----------------------- drivers/gpu/drm/amd/acp/acp_hw.h | 22 +-------------- 2 files changed, 27 insertions(+), 56 deletions(-)
drivers/gpu/drm/amd/acp/acp_hw.c +26 -35
@@ -131,7 +131,7 @@ static void config_dma_descriptor_in_sram(struct amd_acp_device *acp_dev,cgs_write_register (acp_prv->cgs_device, mmACP_SRBM_Targ_Idx_Addr, (sram_offset +8 ));cgs_write_register (acp_prv->cgs_device, mmACP_SRBM_Targ_Idx_Data, - descr_info->size_xfer_dir.val); + descr_info->xfer_val); }/* Initialize the DMA descriptor information for transfer between
@@ -147,48 +147,44 @@ static void set_acp_sysmem_dma_descriptors(struct amd_acp_device *acp_dev, num_descr =2 ; - dmadscr[0 ].size_xfer_dir.val = (u32 )0x0 ; + dmadscr[0 ].xfer_val =0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH12 ; dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_1_ADDRESS + (size /2 ); dmadscr[0 ].src =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ); - dmadscr[0 ].size_xfer_dir.s.trans_direction = -ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM ; - dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x0 ; + dmadscr[0 ].xfer_val |= (DISABLE <<22 ) | + (ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM <<16 ) | + (size /2 ); }else { dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH14 ; dmadscr[0 ].src =ACP_SHARED_RAM_BANK_5_ADDRESS ; dmadscr[0 ].dest =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ); - dmadscr[0 ].size_xfer_dir.s.trans_direction = -ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION ; - dmadscr[0 ].size_xfer_dir.s.size = size /2 ; - dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ; + dmadscr[0 ].xfer_val |= + (ENABLE <<22 ) | + (ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION <<16 ) | + (size /2 ); }config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[0 ]); - dmadscr[1 ].size_xfer_dir.val = (u32 )0x0 ; + dmadscr[1 ].xfer_val =0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_END_DMA_DESCR_CH12 ; dmadscr[1 ].dest =ACP_SHARED_RAM_BANK_1_ADDRESS ; dmadscr[1 ].src =ACP_INTERNAL_APERTURE_WINDOW_0_ADDRESS + (pte_offset *PAGE_SIZE_4K ) + (size /2 ); - dmadscr[1 ].size_xfer_dir.s.trans_direction = -ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM ; - dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x0 ; + dmadscr[1 ].xfer_val |= (DISABLE <<22 ) | + (ACP_DMA_ATTRIBUTES_DAGB_ONION_TO_SHAREDMEM <<16 ) | + (size /2 ); }else { dma_dscr_idx =CAPTURE_END_DMA_DESCR_CH14 ; - dmadscr[1 ].size_xfer_dir.s.trans_direction = -ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION ; - dmadscr[1 ].size_xfer_dir.val = (u32 )0x0 ; dmadscr[1 ].dest = dmadscr[0 ].dest + (size /2 ); dmadscr[1 ].src = dmadscr[0 ].src + (size /2 ); - dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x1 ; + dmadscr[1 ].xfer_val |= (ENABLE <<22 ) | + (ACP_DMA_ATTRIBUTES_SHAREDMEM_TO_DAGB_ONION <<16 ) | + (size /2 ); }config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[1 ]);
@@ -221,37 +217,32 @@ static void set_acp_to_i2s_dma_descriptors(struct amd_acp_device *acp_dev, num_descr =2 ; - dmadscr[0 ].size_xfer_dir.val = (u32 )0x0 ; + dmadscr[0 ].xfer_val =0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_START_DMA_DESCR_CH13 ; dmadscr[0 ].src =ACP_SHARED_RAM_BANK_1_ADDRESS ; - dmadscr[0 ].size_xfer_dir.s.trans_direction =TO_ACP_I2S_1 ; - dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ; + dmadscr[0 ].xfer_val |= (ENABLE <<22 ) | (TO_ACP_I2S_1 <<16 ) | + (size /2 ); }else { dma_dscr_idx =CAPTURE_START_DMA_DESCR_CH15 ; dmadscr[0 ].dest =ACP_SHARED_RAM_BANK_5_ADDRESS ; - dmadscr[0 ].size_xfer_dir.s.trans_direction =FROM_ACP_I2S_1 ; - dmadscr[0 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[0 ].size_xfer_dir.s.ioc = (u32 )0x1 ; + dmadscr[0 ].xfer_val |= (ENABLE <<22 ) | + (FROM_ACP_I2S_1 <<16 ) | (size /2 ); }config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[0 ]); - dmadscr[1 ].size_xfer_dir.val = (u32 )0x0 ; + dmadscr[1 ].xfer_val =0 ;if (direction ==STREAM_PLAYBACK ) { dma_dscr_idx =PLAYBACK_END_DMA_DESCR_CH13 ; dmadscr[1 ].src = dmadscr[0 ].src + (size /2 ); - dmadscr[1 ].size_xfer_dir.s.trans_direction =TO_ACP_I2S_1 ; - dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x1 ; - + dmadscr[1 ].xfer_val |= (ENABLE <<22 ) | (TO_ACP_I2S_1 <<16 ) | + (size /2 ); }else { dma_dscr_idx =CAPTURE_END_DMA_DESCR_CH15 ; dmadscr[1 ].dest = dmadscr[0 ].dest + (size /2 ); - dmadscr[1 ].size_xfer_dir.s.trans_direction =FROM_ACP_I2S_1 ; - dmadscr[1 ].size_xfer_dir.s.size = (size /2 ); - dmadscr[1 ].size_xfer_dir.s.ioc = (u32 )0x1 ; + dmadscr[1 ].xfer_val |= (ENABLE <<22 ) | + (FROM_ACP_I2S_1 <<16 ) | (size /2 ); }config_dma_descriptor_in_sram (acp_dev, dma_dscr_idx, &dmadscr[1 ]);
drivers/gpu/drm/amd/acp/acp_hw.h +1 -21
@@ -73,26 +73,6 @@ enum {ACP_DMA_ATTRIBUTES_FORCE_SIZE =0xF }; -typedef struct acp_dma_dscr_size_transfer_direction { -/* Specifies the number of bytes need to be transferred -* from source to destination memory. */ -u32 size:16 ; -/* Specifies transfer direction. */ -u32 trans_direction:4 ; -/* reserved. */ -u32 reserved1:2 ; -/* Specifies the IOC enable or not for descriptor. */ -/* Defaultly this will be 0, for the last descriptor, make it Enable */ -u32 ioc:1 ; -/* reserved. */ -u32 reserved2:9 ; -}acp_dma_dscr_size_transfer_direction_t ; - -typedef union { -u32 val:32 ; -acp_dma_dscr_size_transfer_direction_t s; -}acp_dma_dscr_size_transfer_direction_u ; - typedef struct acp_dma_dscr_transfer { /* Specifies the source memory location for the DMA data transfer. */ u32 src;
@@ -103,7 +83,7 @@ typedef struct acp_dma_dscr_transfer {/* Specifies the number of bytes need to be transferred * from source to destination memory.Transfer direction & IOC enable */ -acp_dma_dscr_size_transfer_direction_u size_xfer_dir; +u32 xfer_val;/** Reserved for future use */ u32 reserved; } acp_dma_dscr_transfer_t;
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 10/12 ASoC: AMD: add AMD ASoC ACP-I2S driver (v2)
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
ACP IP block consists of dedicated DMA and I2S blocks. The PCM driver provides the DMA and CPU DAI components to ALSA core. Machine driver provides the audio functionality together with the PCM driver and rt286 codec driver.
v2: squash in Kconfig fix
--- sound/soc/Kconfig | 2 +- sound/soc/Makefile | 1 + sound/soc/amd/Kconfig | 13 + sound/soc/amd/Makefile | 11 + sound/soc/amd/acp-pcm-dma.c | 661 ++++++++++++++++++++++++++++++++++++++++++++ sound/soc/amd/acp-rt286.c | 265 ++++++++++++++++++ 6 files changed, 952 insertions(+), 1 deletion(-) create mode 100644 sound/soc/amd/Kconfig create mode 100644 sound/soc/amd/Makefile create mode 100644 sound/soc/amd/acp-pcm-dma.c create mode 100644 sound/soc/amd/acp-rt286.c
sound/soc/Kconfig +1 -1
@@ -32,6 +32,7 @@ config SND_SOC_GENERIC_DMAENGINE_PCM # All the supported SoCs source "sound/soc/adi/Kconfig" +source "sound/soc/amd/Kconfig" source "sound/soc/atmel/Kconfig" source "sound/soc/au1x/Kconfig" source "sound/soc/bcm/Kconfig"
@@ -67,4 +68,3 @@ source "sound/soc/codecs/Kconfig" source "sound/soc/generic/Kconfig" endif # SND_SOC -
sound/soc/Makefile +1 -0
@@ -41,3 +41,4 @@ obj-$(CONFIG_SND_SOC) += txx9/ obj-$(CONFIG_SND_SOC) += ux500/ obj-$(CONFIG_SND_SOC) += xtensa/ obj-$(CONFIG_SND_SOC) += zte/ +obj-$(CONFIG_SND_SOC) += amd/
sound/soc/amd/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ + config SND_SOC_AMD_CZ_RT286_MACH + tristate "AMD ASoC Audio driver for Carrizo with rt286 codec" + select SND_SOC_RT286 + select SND_SOC_AMD_ACP + depends on I2C_DESIGNWARE_PLATFORM + help + This option enables AMD I2S Audio support on Carrizo + with ALC288 codec. + config SND_SOC_AMD_ACP + tristate "AMD Audio Coprocessor support" + depends on DRM_AMD_GNB_BUS + help + This option enables ACP support (DMA,I2S) on AMD platforms.
sound/soc/amd/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amdsoc/ +ccflags-y += -Idrivers/gpu/drm/amdsoc/include/ +ccflags-y += -Idrivers/gpu/drm/amd/include/bus/ +ccflags-y += -Idrivers/gpu/drm/amd/acp/include +ccflags-y += -Idrivers/gpu/drm/amd/include/ +ccflags-y += -Idrivers/gpu/drm/amd/include/asic_reg/acp +snd-soc-acp-pcm-objs := acp-pcm-dma.o +snd-soc-acp-rt286-mach-objs := acp-rt286.o + +obj-$(CONFIG_SND_SOC_AMD_ACP) += snd-soc-acp-pcm.o +obj-$(CONFIG_SND_SOC_AMD_CZ_RT286_MACH) += snd-soc-acp-rt286-mach.o
sound/soc/amd/acp-pcm-dma.c new file +661 -0
661 lines not on this page · raw message
sound/soc/amd/acp-rt286.c new file +265 -0
265 lines not on this page · raw message
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Mark Brown
maintainerRe: [PATCH 10/12] ASoC: AMD: add AMD ASoC ACP-I2S driver (v2)
Quoted 6 lines · Alex Deucher
From: Maruthi Srinivas Bayyavarapu <[email protected]>
ACP IP block consists of dedicated DMA and I2S blocks. The PCM driver provides the DMA and CPU DAI components to ALSA core. Machine driver provides the audio functionality together with the PCM driver and rt286 codec driver.
Quite a few comments below, a lot of them fairly simple stylistic and process ones but there seem to be some really big issues in the way the machine driver is implemented and in particular with things being manually registered rather than instantiated with ACPI. I'm also worried about the unusual licensing.
Please also coordinate with Intel on ACPI bindings for ASoC style audio subsystems, I've CCed in Vinod who's been working on it (and Liam is also at Intel).
Quoted 2 lines
v2: squash in
Kconfigfix
Please follow the patch submission process in SubmittingPatches: put any versioning in the subject line inside the [] and put noise like inter version changelogs after the ---.
sound/soc/Makefile obj-$(CONFIG_SND_SOC) += txx9/ · line 44
Quoted 7 lines
sound/soc/Makefile +1
-0@@ -41,3 +41,4 @@ obj-$(CONFIG_SND_SOC) += txx9/ obj-$(CONFIG_SND_SOC) += ux500/ obj-$(CONFIG_SND_SOC) += xtensa/ obj-$(CONFIG_SND_SOC) += zte/ +obj-$(CONFIG_SND_SOC) += amd/
Please keep the Makefile sorted as well as the Kconfig.
Quoted 6 lines
sound/soc/amd/Kconfig new file +0
-0
sound/soc/amd/Kconfig line 8
Quoted 8 lines
sound/soc/amd/Kconfig new file +8
-0@@ -0,0 +1,13 @@ + config SND_SOC_AMD_CZ_RT286_MACH + tristate "AMD ASoC Audio driver for Carrizo with rt286 codec" + select SND_SOC_RT286 + select SND_SOC_AMD_ACP + depends on I2C_DESIGNWARE_PLATFORM + help + This option enables AMD I2S Audio support on Carrizo + with ALC288 codec.
It looks like you've got tab/space here. You're also adding a machine driver in the same patch as the base driver support, please don't do that - send one patch per driver.
sound/soc/amd/Makefile line 6
Quoted 11 lines
new file mode 100644
index 0000000..63b6f83sound/soc/amd/Makefile new file +6
-0@@ -0,0 +1,11 @@ +ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amdsoc/ +ccflags-y += -Idrivers/gpu/drm/amdsoc/include/ +ccflags-y += -Idrivers/gpu/drm/amd/include/bus/ +ccflags-y += -Idrivers/gpu/drm/amd/acp/include +ccflags-y += -Idrivers/gpu/drm/amd/include/ +ccflags-y += -Idrivers/gpu/drm/amd/include/asic_reg/acp
Eew, no - please put these headers in include.
Quoted 11 lines
sound/soc/amd/Makefile new file +11
-0+ * AMD ALSA SoC PCM Driver + * + * Copyright 2014-2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + *
sound/soc/amd/Makefile
Quoted 10 lines
sound/soc/amd/Makefile new file +10
-0+ * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE.
All the ASoC APIs are EXPORT_SYMBOL_GPL() and this doesn't explicitly grant GPL rights. Your MODULE_LICENSE() says
Quoted 1 line
+MODULE_LICENSE("GPL and additional rights");
but I'm not 100% sure that's the case - it looks like a separate MIT/BSD license rather than a GPL grant. This doesn't make me happy about the licensing status. The clearest thing would be either to just license under the GPL, or to dual license.
sound/soc/amd/Makefile
Quoted 1 line
sound/soc/amd/Makefile new file +1
-0+ .fifo_size = 0,
No need to set static structures to 0.
sound/soc/amd/Makefile
Quoted 3 lines
sound/soc/amd/Makefile new file +3
-0+static const struct snd_soc_component_driver dw_i2s_component = { + .name = "dw-i2s.0", +};
.0? What's going on here...
sound/soc/amd/Makefile
Quoted 6 lines
sound/soc/amd/Makefile new file +6
-0+static void acp_pcm_period_elapsed(struct device *dev, u16 play_intr, + u16 capture_intr) +{ + struct snd_pcm_substream *substream; + struct audio_drv_data *irq_data = + (struct audio_drv_data *)dev_get_drvdata(dev);
No need to cast away from void.
sound/soc/amd/Makefile
Quoted 8 lines
sound/soc/amd/Makefile new file +8
-0+ + /* Inform ALSA about the period elapsed (one out of two periods) */ + if (play_intr) + substream = irq_data->play_stream; + else if (capture_intr) + substream = irq_data->capture_stream; + + if (substream->runtime && snd_pcm_running(substream))
What if both play_intr and capture_intr or set, or if neither of them is set?
sound/soc/amd/Makefile
Quoted 6 lines
sound/soc/amd/Makefile new file +6
-0+ adata->dma_config = + kzalloc(sizeof(struct acp_dma_config), GFP_KERNEL); + if (adata->dma_config == NULL) { + kfree(adata); + return -ENOMEM; + }
Why are all these structs allocated separately and not just embedded into adata?
sound/soc/amd/Makefile
Quoted 8 lines
sound/soc/amd/Makefile new file +8
-0+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + runtime->hw = acp_pcm_hardware_playback; + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) + runtime->hw = acp_pcm_hardware_capture; + else { + pr_err("Error in stream type\n"); + return -EINVAL; + }
You should have { } on all branches of an if statement if you need it on one. The usual idiom for this check is just to do "if (playback)" and not have the third error case.
sound/soc/amd/Makefile
Quoted 4 lines
sound/soc/amd/Makefile new file +4
-0+ ret = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + if (ret < 0) { + pr_err("snd_pcm_hw_constraint_integer failed\n");
Please use dev_ prints so people can tell more easily what the source of the message is.
sound/soc/amd/Makefile
Quoted 2 lines
sound/soc/amd/Makefile new file +2
-0+ if (WARN_ON(!substream)) + return -EINVAL;
The subsystem will check this for you.
sound/soc/amd/Makefile
Quoted 10 lines
sound/soc/amd/Makefile new file +10
-0+ memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); + pg = virt_to_page(substream->dma_buffer.area); + + if (NULL != pg) { + /* Save for runtime private data */ + rtd->pg = pg; + rtd->order = get_order(size); + + /*Let ACP know the Allocated memory */ + num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
Spaces in the comments.
sound/soc/amd/Makefile
Quoted 13 lines
sound/soc/amd/Makefile new file +13
-0+ /* Fill ACP SRAM with zeros from System RAM which is zero-ed + * in hw_params */ + ret = acp_dev->dma_start(rtd->acp_dev, + SYSRAM_TO_ACP_CH_NUM, false); + if (ret < 0) + ret = -EFAULT; + + /* Now configure DMA to transfer only first half of System RAM + * buffer before playback is triggered. This will overwrite + * zero-ed second half of SRAM buffer */ + acp_dev->config_dma_channel(acp_dev, SYSRAM_TO_ACP_CH_NUM, + PLAYBACK_START_DMA_DESCR_CH12, + 1, 0);
Why? The comments describe what's happening but it's not clear why it's happening.
sound/soc/amd/Makefile
Quoted 7 lines
sound/soc/amd/Makefile new file +7
-0+static int acp_dma_trigger(struct snd_pcm_substream *substream, int cmd) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct audio_substream_data *rtd = runtime->private_data; + struct amd_acp_device *acp_dev = rtd->acp_dev; + + int ret = -EIO;
This means the compiler won't be able to spot missing initialisation problems - do we need to do it? Also I notice you've got a *lot* of blocks of variable declarations separated by spaces which is really unusual for the kernel.
sound/soc/amd/Makefile
Quoted 11 lines
sound/soc/amd/Makefile new file +11
-0+ if (!rtd) + return -EINVAL; + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + ret = acp_dev->dma_start(rtd->acp_dev, + SYSRAM_TO_ACP_CH_NUM, false); + if (ret < 0) + ret = -EFAULT;
Don't ignore the error code you got, pass it back.
sound/soc/amd/Makefile
Quoted 3 lines
sound/soc/amd/Makefile new file +3
-0+ default: + dev_err(dev, "designware-i2s: unsuppted PCM fmt"); + return -EINVAL;
This doesn't appear to be a designware-i2s driver, we already have one of those? It's also better to print out the value that we're erroring on, it can help people figure out problems.
sound/soc/amd/Makefile
Quoted 7 lines
sound/soc/amd/Makefile new file +7
-0+static int acp_alsa_register(struct device *dev, struct amd_acp_device *acp_dev, + struct amd_gnb_bus_dev *adev) +{ + int status; + + status = snd_soc_register_platform(dev, &acp_asoc_platform); + if (STATUS_SUCCESS != status) {
STATUS_SUCCESS!? It's also very unusual to have the variable and the constant this way round in the kernel - I am noticing a lot of style issues in here.
sound/soc/amd/Makefile
Quoted 3 lines
sound/soc/amd/Makefile new file +3
-0+static void __exit amdsoc_bus_acp_dma_driver_exit(void) +{ + pr_info("ACP: PCM driver exit\n");
Don't include noise like this in the kernel logs, it's not adding anything.
sound/soc/amd/Makefile
Quoted 9 lines
sound/soc/amd/Makefile new file +9
-0+ amd_gnb_bus_unregister_driver(&acp_dma_driver); +} + +module_init(amdsoc_bus_acp_dma_driver_init); +module_exit(amdsoc_bus_acp_dma_driver_exit); + +MODULE_AUTHOR("[email protected]"); +MODULE_DESCRIPTION("AMD ACP PCM Driver"); +MODULE_LICENSE("GPL and additional rights");
How will this module get autoloaded?
sound/soc/amd/Makefile
Quoted 5 lines
sound/soc/amd/Makefile new file +5
-0+#include "../codecs/rt286.h" + +#ifdef CONFIG_PINCTRL_AMD + +#define CZ_HPJACK_GPIO 7
Hard coded system wide magic numbers? Please don't do this.
sound/soc/amd/Makefile
Quoted 7 lines
sound/soc/amd/Makefile new file +7
-0+ err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBM_CFM); + if (err < 0) { + dev_err(card->dev, "unable to set codec dai format\n"); + return err; + }
Set this in the dai_link.
sound/soc/amd/Makefile
Quoted 6 lines
sound/soc/amd/Makefile new file +6
-0+ err = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, + SND_SOC_CLOCK_OUT); + if (err < 0) { + dev_err(card->dev, "unable to set codec dai clock\n"); + return err; + }
Set this in the link init function, no need to reset it each time we configure since it never changes.
sound/soc/amd/Makefile
Quoted 4 lines
sound/soc/amd/Makefile new file +4
-0+static int carrizo_init(struct snd_soc_pcm_runtime *rtd) +{ + /* TODO: check whether dapm widgets needs to be + * dsiconnected initially. */
They don't.
sound/soc/amd/Makefile
Quoted 9 lines
sound/soc/amd/Makefile new file +9
-0+static struct snd_soc_dai_link carrizo_dai_rt286 = { + .name = "amd-rt286", + .stream_name = "RT286_AIF1", + .platform_name = "acp_pcm_dev", + .cpu_dai_name = "acp_pcm_dev", + .codec_dai_name = "rt286-aif1", + .codec_name = "rt286.3-001c", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM,
Oh, you did initialise this in the dai_link :(
sound/soc/amd/Makefile
Quoted 1 line
sound/soc/amd/Makefile new file +1
-0+ .ignore_suspend = 1,
Why is this being set - this doesn't look like it's a CODEC<->CODEC link?
sound/soc/amd/Makefile
Quoted 2 lines
sound/soc/amd/Makefile new file +2
-0+ ret = snd_soc_register_card(card); + if (ret) {
devm_snd_soc_register_card()
sound/soc/amd/Makefile
Quoted 4 lines
sound/soc/amd/Makefile new file +4
-0+static const struct acpi_device_id cz_audio_acpi_match[] = { + { "I2SC1002", 0 }, + {}, +};
ACPI has bindings for GPIOs, you should be able to use those to discover the detection GPIO.
Quoted 11 lines
sound/soc/amd/Makefile new file +11
-0+static int __init cz_audio_init(void) +{ + int ret; + struct i2c_adapter *adapter; + struct i2c_board_info cz_board_info; + const char *codec_acpi_name = "rt288"; + + adapter = i2c_get_adapter(CZ_CODEC_I2C_ADAPTER_ID); + if (!adapter) + return -ENODEV; +
sound/soc/amd/Makefile
Quoted 10 lines
sound/soc/amd/Makefile new file +10
-0+ memset(&cz_board_info, 0, sizeof(struct i2c_board_info)); + cz_board_info.addr = CZ_CODEC_I2C_ADDR; + strlcpy(cz_board_info.type, codec_acpi_name, I2C_NAME_SIZE); + +#ifdef CONFIG_PINCTRL_AMD + if (gpio_is_valid(CZ_HPJACK_GPIO)) { + ret = gpio_request_one(CZ_HPJACK_GPIO, GPIOF_DIR_IN | + GPIOF_EXPORT, "hp-gpio"); + if (ret != 0) + pr_err("gpio_request_one failed : err %d\n", ret);
As well as the whole thing with getting this from ACPI rather than defining magic numbers this should be done in the card init not in the module init (like other card drivers do). This then means you don't need any global variables.
sound/soc/amd/Makefile
Quoted 5 lines
sound/soc/amd/Makefile new file +5
-0+#endif + i2c_client = i2c_new_device(adapter, &cz_board_info); + i2c_put_adapter(adapter); + if (!i2c_client) + return -ENODEV;
No, definitely not - ACPI has perfectly good bindings for instantiating I2C devices (indeed the laptop I'm typing this on actually uses them to instantiate exactly the same RT286 audio CODEC you're using here), please use them.
Re: [PATCH 10/12] ASoC: AMD: add AMD ASoC ACP-I2S driver (v2)
Hi Mark,
Thanks, I will work on the review feedback.
Regards,
Maruthi
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: 07 August 2015 00:52
To: Alex Deucher
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bayyavarapu, Maruthi; Vinod Koul
Subject: Re: [PATCH 10/12] ASoC: AMD: add AMD ASoC ACP-I2S driver (v2)
Quoted 6 lines · Alex Deucher
From: Maruthi Srinivas Bayyavarapu <[email protected]>
ACP IP block consists of dedicated DMA and I2S blocks. The PCM driver provides the DMA and CPU DAI components to ALSA core. Machine driver provides the audio functionality together with the PCM driver and rt286 codec driver.
Quite a few comments below, a lot of them fairly simple stylistic and process ones but there seem to be some really big issues in the way the machine driver is implemented and in particular with things being manually registered rather than instantiated with ACPI. I'm also worried about the unusual licensing.
Please also coordinate with Intel on ACPI bindings for ASoC style audio subsystems, I've CCed in Vinod who's been working on it (and Liam is also at Intel).
Quoted 2 lines
v2: squash in
Kconfigfix
Please follow the patch submission process in SubmittingPatches: put any versioning in the subject line inside the [] and put noise like inter version changelogs after the ---.
sound/soc/Makefile obj-$(CONFIG_SND_SOC) += txx9/ · line 44
Quoted 7 lines
sound/soc/Makefile +1
-0@@ -41,3 +41,4 @@ obj-$(CONFIG_SND_SOC) += txx9/ obj-$(CONFIG_SND_SOC) += ux500/ obj-$(CONFIG_SND_SOC) += xtensa/ obj-$(CONFIG_SND_SOC) += zte/ +obj-$(CONFIG_SND_SOC) += amd/
Please keep the Makefile sorted as well as the Kconfig.
sound/soc/amd/Kconfig line 8
Quoted 13 lines
sound/soc/amd/Kconfig new file renamed from sound/soc/amd/Kconfig +0
-0mode 100644 index 0000000..07677de
sound/soc/amd/Kconfig new file +8
-0@@ -0,0 +1,13 @@ + config SND_SOC_AMD_CZ_RT286_MACH + tristate "AMD ASoC Audio driver for Carrizo with rt286 codec" + select SND_SOC_RT286 + select SND_SOC_AMD_ACP + depends on I2C_DESIGNWARE_PLATFORM + help + This option enables AMD I2S Audio support on Carrizo + with ALC288 codec.
It looks like you've got tab/space here. You're also adding a machine driver in the same patch as the base driver support, please don't do that - send one patch per driver.
sound/soc/amd/Makefile line 6
Quoted 11 lines
new file mode 100644
index 0000000..63b6f83sound/soc/amd/Makefile new file +6
-0@@ -0,0 +1,11 @@ +ccflags-y := -Iinclude/drm -Idrivers/gpu/drm/amdsoc/ ccflags-y += +-Idrivers/gpu/drm/amdsoc/include/ +ccflags-y += -Idrivers/gpu/drm/amd/include/bus/ +ccflags-y += -Idrivers/gpu/drm/amd/acp/include ccflags-y += +-Idrivers/gpu/drm/amd/include/ ccflags-y += +-Idrivers/gpu/drm/amd/include/asic_reg/acp
Eew, no - please put these headers in include.
Quoted 23 lines
sound/soc/amd/Makefile new file +23
-0+ * AMD ALSA SoC PCM Driver + * + * Copyright 2014-2015 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person + obtaining a + * copy of this software and associated documentation files (the + "Software"), + * to deal in the Software without restriction, including without + limitation + * the rights to use, copy, modify, merge, publish, distribute, + sublicense, + * and/or sell copies of the Software, and to permit persons to whom + the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
sound/soc/amd/Makefile
Quoted 10 lines
sound/soc/amd/Makefile new file +10
-0+ MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT + SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, + DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE + OR + * OTHER DEALINGS IN THE SOFTWARE.
All the ASoC APIs are EXPORT_SYMBOL_GPL() and this doesn't explicitly grant GPL rights. Your MODULE_LICENSE() says
Quoted 1 line
+MODULE_LICENSE("GPL and additional rights");
but I'm not 100% sure that's the case - it looks like a separate MIT/BSD license rather than a GPL grant. This doesn't make me happy about the licensing status. The clearest thing would be either to just license under the GPL, or to dual license.
sound/soc/amd/Makefile
Quoted 1 line
sound/soc/amd/Makefile new file +1
-0+ .fifo_size = 0,
No need to set static structures to 0.
sound/soc/amd/Makefile
Quoted 3 lines
sound/soc/amd/Makefile new file +3
-0+static const struct snd_soc_component_driver dw_i2s_component = { + .name = "dw-i2s.0", +};
.0? What's going on here...
sound/soc/amd/Makefile
Quoted 6 lines
sound/soc/amd/Makefile new file +6
-0+static void acp_pcm_period_elapsed(struct device *dev, u16 play_intr, + u16 capture_intr) +{ + struct snd_pcm_substream *substream; + struct audio_drv_data *irq_data = + (struct audio_drv_data *)dev_get_drvdata(dev);
No need to cast away from void.
sound/soc/amd/Makefile
Quoted 8 lines
sound/soc/amd/Makefile new file +8
-0+ + /* Inform ALSA about the period elapsed (one out of two periods) */ + if (play_intr) + substream = irq_data->play_stream; + else if (capture_intr) + substream = irq_data->capture_stream; + + if (substream->runtime && snd_pcm_running(substream))
What if both play_intr and capture_intr or set, or if neither of them is set?
sound/soc/amd/Makefile
Quoted 6 lines
sound/soc/amd/Makefile new file +6
-0+ adata->dma_config = + kzalloc(sizeof(struct acp_dma_config), GFP_KERNEL); + if (adata->dma_config == NULL) { + kfree(adata); + return -ENOMEM; + }
Why are all these structs allocated separately and not just embedded into adata?
sound/soc/amd/Makefile
Quoted 8 lines
sound/soc/amd/Makefile new file +8
-0+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) + runtime->hw = acp_pcm_hardware_playback; + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) + runtime->hw = acp_pcm_hardware_capture; + else { + pr_err("Error in stream type\n"); + return -EINVAL; + }
You should have { } on all branches of an if statement if you need it on one. The usual idiom for this check is just to do "if (playback)" and not have the third error case.
sound/soc/amd/Makefile
Quoted 4 lines
sound/soc/amd/Makefile new file +4
-0+ ret = snd_pcm_hw_constraint_integer(runtime, + SNDRV_PCM_HW_PARAM_PERIODS); + if (ret < 0) { + pr_err("snd_pcm_hw_constraint_integer failed\n");
Please use dev_ prints so people can tell more easily what the source of the message is.
sound/soc/amd/Makefile
Quoted 2 lines
sound/soc/amd/Makefile new file +2
-0+ if (WARN_ON(!substream)) + return -EINVAL;
The subsystem will check this for you.
sound/soc/amd/Makefile
Quoted 10 lines
sound/soc/amd/Makefile new file +10
-0+ memset(substream->runtime->dma_area, 0, params_buffer_bytes(params)); + pg = virt_to_page(substream->dma_buffer.area); + + if (NULL != pg) { + /* Save for runtime private data */ + rtd->pg = pg; + rtd->order = get_order(size); + + /*Let ACP know the Allocated memory */ + num_of_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
Spaces in the comments.
sound/soc/amd/Makefile
Quoted 13 lines
sound/soc/amd/Makefile new file +13
-0+ /* Fill ACP SRAM with zeros from System RAM which is zero-ed + * in hw_params */ + ret = acp_dev->dma_start(rtd->acp_dev, + SYSRAM_TO_ACP_CH_NUM, false); + if (ret < 0) + ret = -EFAULT; + + /* Now configure DMA to transfer only first half of System RAM + * buffer before playback is triggered. This will overwrite + * zero-ed second half of SRAM buffer */ + acp_dev->config_dma_channel(acp_dev, SYSRAM_TO_ACP_CH_NUM, + PLAYBACK_START_DMA_DESCR_CH12, + 1, 0);
Why? The comments describe what's happening but it's not clear why it's happening.
sound/soc/amd/Makefile
Quoted 7 lines
sound/soc/amd/Makefile new file +7
-0+static int acp_dma_trigger(struct snd_pcm_substream *substream, int +cmd) { + struct snd_pcm_runtime *runtime = substream->runtime; + struct audio_substream_data *rtd = runtime->private_data; + struct amd_acp_device *acp_dev = rtd->acp_dev; + + int ret = -EIO;
This means the compiler won't be able to spot missing initialisation problems - do we need to do it? Also I notice you've got a *lot* of blocks of variable declarations separated by spaces which is really unusual for the kernel.
sound/soc/amd/Makefile
Quoted 11 lines
sound/soc/amd/Makefile new file +11
-0+ if (!rtd) + return -EINVAL; + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + case SNDRV_PCM_TRIGGER_RESUME: + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + ret = acp_dev->dma_start(rtd->acp_dev, + SYSRAM_TO_ACP_CH_NUM, false); + if (ret < 0) + ret = -EFAULT;
Don't ignore the error code you got, pass it back.
sound/soc/amd/Makefile
Quoted 3 lines
sound/soc/amd/Makefile new file +3
-0+ default: + dev_err(dev, "designware-i2s: unsuppted PCM fmt"); + return -EINVAL;
This doesn't appear to be a designware-i2s driver, we already have one of those? It's also better to print out the value that we're erroring on, it can help people figure out problems.
sound/soc/amd/Makefile
Quoted 7 lines
sound/soc/amd/Makefile new file +7
-0+static int acp_alsa_register(struct device *dev, struct amd_acp_device *acp_dev, + struct amd_gnb_bus_dev *adev) +{ + int status; + + status = snd_soc_register_platform(dev, &acp_asoc_platform); + if (STATUS_SUCCESS != status) {
STATUS_SUCCESS!? It's also very unusual to have the variable and the constant this way round in the kernel - I am noticing a lot of style issues in here.
sound/soc/amd/Makefile
Quoted 3 lines
sound/soc/amd/Makefile new file +3
-0+static void __exit amdsoc_bus_acp_dma_driver_exit(void) +{ + pr_info("ACP: PCM driver exit\n");
Don't include noise like this in the kernel logs, it's not adding anything.
sound/soc/amd/Makefile
Quoted 9 lines
sound/soc/amd/Makefile new file +9
-0+ amd_gnb_bus_unregister_driver(&acp_dma_driver); +} + +module_init(amdsoc_bus_acp_dma_driver_init); +module_exit(amdsoc_bus_acp_dma_driver_exit); + +MODULE_AUTHOR("[email protected]"); +MODULE_DESCRIPTION("AMD ACP PCM Driver"); MODULE_LICENSE("GPL and +additional rights");
How will this module get autoloaded?
sound/soc/amd/Makefile
Quoted 5 lines
sound/soc/amd/Makefile new file +5
-0+#include "../codecs/rt286.h" + +#ifdef CONFIG_PINCTRL_AMD + +#define CZ_HPJACK_GPIO 7
Hard coded system wide magic numbers? Please don't do this.
sound/soc/amd/Makefile
Quoted 7 lines
sound/soc/amd/Makefile new file +7
-0+ err = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | + SND_SOC_DAIFMT_NB_NF | + SND_SOC_DAIFMT_CBM_CFM); + if (err < 0) { + dev_err(card->dev, "unable to set codec dai format\n"); + return err; + }
Set this in the dai_link.
sound/soc/amd/Makefile
Quoted 6 lines
sound/soc/amd/Makefile new file +6
-0+ err = snd_soc_dai_set_sysclk(codec_dai, RT286_SCLK_S_PLL, 24000000, + SND_SOC_CLOCK_OUT); + if (err < 0) { + dev_err(card->dev, "unable to set codec dai clock\n"); + return err; + }
Set this in the link init function, no need to reset it each time we configure since it never changes.
sound/soc/amd/Makefile
Quoted 3 lines
sound/soc/amd/Makefile new file +3
-0+static int carrizo_init(struct snd_soc_pcm_runtime *rtd) { + /* TODO: check whether dapm widgets needs to be + * dsiconnected initially. */
They don't.
sound/soc/amd/Makefile
Quoted 9 lines
sound/soc/amd/Makefile new file +9
-0+static struct snd_soc_dai_link carrizo_dai_rt286 = { + .name = "amd-rt286", + .stream_name = "RT286_AIF1", + .platform_name = "acp_pcm_dev", + .cpu_dai_name = "acp_pcm_dev", + .codec_dai_name = "rt286-aif1", + .codec_name = "rt286.3-001c", + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF + | SND_SOC_DAIFMT_CBM_CFM,
Oh, you did initialise this in the dai_link :(
sound/soc/amd/Makefile
Quoted 1 line
sound/soc/amd/Makefile new file +1
-0+ .ignore_suspend = 1,
Why is this being set - this doesn't look like it's a CODEC<->CODEC link?
sound/soc/amd/Makefile
Quoted 2 lines
sound/soc/amd/Makefile new file +2
-0+ ret = snd_soc_register_card(card); + if (ret) {
devm_snd_soc_register_card()
sound/soc/amd/Makefile
Quoted 4 lines
sound/soc/amd/Makefile new file +4
-0+static const struct acpi_device_id cz_audio_acpi_match[] = { + { "I2SC1002", 0 }, + {}, +};
ACPI has bindings for GPIOs, you should be able to use those to discover the detection GPIO.
Quoted 10 lines
sound/soc/amd/Makefile new file +10
-0+static int __init cz_audio_init(void) { + int ret; + struct i2c_adapter *adapter; + struct i2c_board_info cz_board_info; + const char *codec_acpi_name = "rt288"; + + adapter = i2c_get_adapter(CZ_CODEC_I2C_ADAPTER_ID); + if (!adapter) + return -ENODEV; +
sound/soc/amd/Makefile
Quoted 10 lines
sound/soc/amd/Makefile new file +10
-0+ memset(&cz_board_info, 0, sizeof(struct i2c_board_info)); + cz_board_info.addr = CZ_CODEC_I2C_ADDR; + strlcpy(cz_board_info.type, codec_acpi_name, I2C_NAME_SIZE); + +#ifdef CONFIG_PINCTRL_AMD + if (gpio_is_valid(CZ_HPJACK_GPIO)) { + ret = gpio_request_one(CZ_HPJACK_GPIO, GPIOF_DIR_IN | + GPIOF_EXPORT, "hp-gpio"); + if (ret != 0) + pr_err("gpio_request_one failed : err %d\n", ret);
As well as the whole thing with getting this from ACPI rather than defining magic numbers this should be done in the card init not in the module init (like other card drivers do). This then means you don't need any global variables.
sound/soc/amd/Makefile
Quoted 5 lines
sound/soc/amd/Makefile new file +5
-0+#endif + i2c_client = i2c_new_device(adapter, &cz_board_info); + i2c_put_adapter(adapter); + if (!i2c_client) + return -ENODEV;
No, definitely not - ACPI has perfectly good bindings for instantiating I2C devices (indeed the laptop I'm typing this on actually uses them to instantiate exactly the same RT286 audio CODEC you're using here), please use them.
PATCH 11/12 ASoC: AMD: add suspend/resume for ACP PCM driver
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
Added suspend/resume functionality for AMD ACP ASoC PCM driver. Enabled them in the ASoC machine driver
--- sound/soc/amd/acp-pcm-dma.c | 31 +++++++++++++++++++++++++++++++ sound/soc/amd/acp-rt286.c | 1 - 2 files changed, 31 insertions(+), 1 deletion(-)
sound/soc/amd/acp-pcm-dma.c +31 -0
@@ -625,11 +625,42 @@ static int acp_amdsoc_remove(struct amd_gnb_bus_dev *adev)return 0 ; } +static int acp_pcm_suspend (struct device *dev) +{ +return 0 ; +} + +static int acp_pcm_resume (struct device *dev) +{ +struct snd_pcm_substream *substream; +struct snd_pcm_runtime *runtime; +struct audio_substream_data *rtd; + +struct audio_drv_data *irq_data = + (struct audio_drv_data *)dev_get_drvdata (dev); + + substream = irq_data->play_stream; + runtime = substream->runtime; + rtd = runtime->private_data; + + irq_data->acp_dev->config_i2s (irq_data->acp_dev, rtd->i2s_config); + irq_data->acp_dev->config_dma (irq_data->acp_dev, rtd->dma_config); + +return 0 ; +} + +static const struct dev_pm_ops acp_pm_ops = { +SET_SYSTEM_SLEEP_PM_OPS (acp_pcm_suspend, acp_pcm_resume) +}; +static struct amd_gnb_bus_driver acp_dma_driver = { .name ="acp-pcm-driver" , .ip =AMD_GNB_IP_ACP_PCM , .probe = acp_amdsoc_probe, .remove = acp_amdsoc_remove, + .driver = { + .pm = &acp_pm_ops, + }, };static int __init amdsoc_bus_acp_dma_driver_init (void )
sound/soc/amd/acp-rt286.c +0 -1
@@ -129,7 +129,6 @@ static struct snd_soc_dai_link carrizo_dai_rt286 = { .codec_name = "rt286.3-001c", .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM, - .ignore_suspend = 1, .ops = &carrizo_rt286_ops, .init = carrizo_init, };
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Mark Brown
maintainerRe: [PATCH 11/12] ASoC: AMD: add suspend/resume for ACP PCM driver
sound/soc/amd/acp-pcm-dma.c static int acp_amdsoc_remove(struct amd_gnb_bus_dev *adev) · line 631
Quoted 4 lines · Alex Deucher
sound/soc/amd/acp-pcm-dma.c +4
-0+static int acp_pcm_suspend (struct device *dev) +{ +return 0 ; +}
You should never need to add empty functions like this.
PATCH 12/12 ASoC: AMD: add ACP PCM driver runtime PM
In reply to Alex DeucherFrom: Maruthi Srinivas Bayyavarapu <[email protected]>
Added runtime PM functionality to AMD I2S driver. This uses functionality from ACP IP methods.
--- sound/soc/amd/acp-pcm-dma.c | 87 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 10 deletions(-)
sound/soc/amd/acp-pcm-dma.c +77 -10
@@ -32,6 +32,7 @@#include <linux/err.h> #include <linux/io.h> #include <linux/pci.h> +#include <linux/pm_runtime.h> #include <sound/pcm.h> #include <sound/pcm_params.h>
@@ -379,10 +380,12 @@ static int acp_dma_close(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;struct audio_substream_data *rtd = runtime->private_data; +struct snd_soc_pcm_runtime *prtd = substream->private_data;kfree (rtd->dma_config);kfree (rtd->i2s_config);kfree (rtd); +pm_runtime_mark_last_busy (prtd->platform->dev);return 0 ; }
@@ -610,6 +613,10 @@ static int acp_amdsoc_probe(struct amd_gnb_bus_dev *adev)else pr_err ("ACP initialization Failed\n" ); +pm_runtime_set_autosuspend_delay (&adev->dev,10000 ); +pm_runtime_use_autosuspend (&adev->dev); +pm_runtime_enable (&adev->dev); +return status; }
@@ -621,36 +628,96 @@ static int acp_amdsoc_remove(struct amd_gnb_bus_dev *adev)snd_soc_unregister_platform (&adev->dev); acp_dev->fini (acp_dev); - +pm_runtime_disable (&adev->dev);return 0 ; }static int acp_pcm_suspend (struct device *dev) { +bool pm_rts; +struct audio_drv_data *adata = + (struct audio_drv_data *)dev_get_drvdata (dev); + + pm_rts =pm_runtime_status_suspended (dev); +if (pm_rts == false) + adata->acp_dev->fini (adata->acp_dev); +return 0 ; }static int acp_pcm_resume (struct device *dev) { -struct snd_pcm_substream *substream; -struct snd_pcm_runtime *runtime; +bool pm_rts; +struct snd_pcm_substream *pstream, *cstream; +struct snd_pcm_runtime *prtd, *crtd;struct audio_substream_data *rtd; -struct audio_drv_data *irq_data = +struct audio_drv_data *adata = (struct audio_drv_data *)dev_get_drvdata (dev); - substream = irq_data->play_stream; - runtime = substream->runtime; - rtd = runtime->private_data; + pm_rts =pm_runtime_status_suspended (dev); +if (pm_rts == true) { +/* Resumed from system wide suspend and there is +* no pending audio activity to resume. */ +pm_runtime_disable (dev); +pm_runtime_set_active (dev); +pm_runtime_enable (dev); + + goto out; + } - irq_data->acp_dev->config_i2s (irq_data->acp_dev, rtd->i2s_config); - irq_data->acp_dev->config_dma (irq_data->acp_dev, rtd->dma_config); + pstream = adata->play_stream; + prtd = pstream ? pstream->runtime :NULL ; +if (prtd !=NULL ) { +/* Resume playback stream from a suspended state */ + rtd = prtd->private_data; + adata->acp_dev->config_dma (adata->acp_dev, rtd->dma_config); + adata->acp_dev->config_i2s (adata->acp_dev, rtd->i2s_config); + } + + cstream = adata->capture_stream; + crtd = cstream ? cstream->runtime :NULL ; +if (crtd !=NULL ) { +/* Resume capture stream from a suspended state */ + rtd = crtd->private_data; + + adata->acp_dev->config_dma (adata->acp_dev, rtd->dma_config); + adata->acp_dev->config_i2s (adata->acp_dev, rtd->i2s_config); + } +out: +return 0 ; +} + +int acp_pcm_runtime_suspend (struct device *dev) +{ +struct audio_drv_data *adata = + (struct audio_drv_data *)dev_get_drvdata (dev); + + adata->acp_dev->acp_suspend (adata->acp_dev); +return 0 ; +} + +int acp_pcm_runtime_resume (struct device *dev) +{ +struct audio_drv_data *adata = + (struct audio_drv_data *)dev_get_drvdata (dev); + + adata->acp_dev->acp_resume (adata->acp_dev); +return 0 ; +} + +int acp_pcm_runtime_idle (struct device *dev) +{return 0 ; }static const struct dev_pm_ops acp_pm_ops = { -SET_SYSTEM_SLEEP_PM_OPS (acp_pcm_suspend, acp_pcm_resume) + .suspend = acp_pcm_suspend, + .resume = acp_pcm_resume, + .runtime_suspend = acp_pcm_runtime_suspend, + .runtime_resume = acp_pcm_runtime_resume, + .runtime_idle = acp_pcm_runtime_idle };static struct amd_gnb_bus_driver acp_dma_driver = {
Signature · 6 lines
1.8.3.1 _______________________________________________ dri-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/dri-devel
Mark Brown
maintainerRe: [PATCH 12/12] ASoC: AMD: add ACP PCM driver runtime PM
Quoted 4 lines · Alex Deucher
From: Maruthi Srinivas Bayyavarapu <[email protected]>
Added runtime PM functionality to AMD I2S driver. This uses functionality from ACP IP methods.
Just add this (and the previous patch) in the driver. The patches are so tiny it's not adding much to split them out like this and it's actually harder to review this one when it's split from the system suspend code.
Re: [PATCH 12/12] ASoC: AMD: add ACP PCM driver runtime PM
Hi Mark,
I will send a another patch-set, with patches combined, as suggested.
Regards,
Maruthi
-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: 07 August 2015 00:57
To: Alex Deucher
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Bayyavarapu, Maruthi
Subject: Re: [PATCH 12/12] ASoC: AMD: add ACP PCM driver runtime PM
Quoted 4 lines · Alex Deucher
From: Maruthi Srinivas Bayyavarapu <[email protected]>
Added runtime PM functionality to AMD I2S driver. This uses functionality from ACP IP methods.
Just add this (and the previous patch) in the driver. The patches are so tiny it's not adding much to split them out like this and it's actually harder to review this one when it's split from the system suspend code.