Skip to content

Commit 3304e69

Browse files
pelwellpopcornmix
authored andcommitted
misc: Add RP1 PIO driver
Provide remote access to the PIO hardware in RP1. There is a single instance, with 4 state machines. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Support larger data transfers Add a separate IOCTL for larger transfer with a 32-bit data_bytes field. See: raspberrypi/utils#107 Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: More logical probe sequence Sort the probe function initialisation into a more logical order. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Minor cosmetic tweaks No functional change. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Add in-kernel DMA support Add kernel-facing implementations of pio_sm_config_xfer and pio_xm_xfer_data. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Handle probe errors Ensure that rp1_pio_open fails if the device failed to probe. Link: #6593 Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: SM_CONFIG_XFER32 = larger DMA bufs Add an ioctl type - SM_CONFIG_XFER32 - that takes uints for the buf_size and buf_count values. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc/rp1-pio: Fix copy/paste error in pio_rp1.h As per the subject, there was a copy/paste error that caused pio_sm_unclaim from a driver to result in a call to pio_sm_claim. Fix it. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Fix parameter checks wihout client Passing bad parameters to an API call without a pio pointer will cause a NULL pointer exception when the persistent error is set. Guard against that. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Convert floats to 24.8 fixed point Floating point arithmetic is not supported in the kernel, so use fixed point instead. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Error out on incompatible firmware If the RP1 firmware has reported an error then return that from the PIO probe function, otherwise defer the probing. Link: #6642 Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Demote fw probe error to warning Support for the RP1 firmware mailbox API is rolling out to Pi 5 EEPROM images. For most users, the fact that the PIO is not available is no cause for alarm. Change the message to a warning, so that it does not appear with "quiet" in cmdline.txt. Link: #6642 Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Don't just reuse the same DMA buf A missing pointer increment meant that not only was the same buffer being reused again and again, there was also no protection against using it simultaneously for multiple transfers. Fix that basic bug, and also move a similar increment to before the transfer is started, which feels less racy. See: #6919 Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Fix a config_xfer error path If the DMA channel allocation fails, the relevant dma_configs entry should be marked as no longer claimed, otherwise rp1_pio_sm_dma_free will be called with an error number as a DMA channel pointer. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Request a DMA burst size of 8 Improve DMA performance by increasing the burst size to 8. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Get burst size from DMA capabilities Although the PIO throughput benefits from larger burst sizes, only the first two DMA channels support a burst size of 8 - the others are capped at 4. To avoid misconfiguring the PIO hardware, retrieve the actual max_burst value from the DMA channel's capabilities. Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Defer for out-of-order probing In the event that a client of the rp1-pio driver is probed before it, return -EPROBE_DEFER from pio_open to allow it to be retried. Otherwise, return an error code on error, not a NULL pointer, as that is what clients are expecting. See: #7211 Signed-off-by: Phil Elwell <phil@raspberrypi.com> misc: rp1-pio: Add narrowing casts Avoid some compiler warnings by adding explicit narrowing casts. See: #7309 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
1 parent b947b57 commit 3304e69

7 files changed

Lines changed: 3209 additions & 0 deletions

File tree

drivers/misc/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ config BCM2835_SMI
1717
Driver for enabling and using Broadcom's Secondary/Slow Memory Interface.
1818
Appears as /dev/bcm2835_smi. For ioctl interface see drivers/misc/bcm2835_smi.h
1919

20+
config RP1_PIO
21+
tristate "Raspberry Pi RP1 PIO driver"
22+
depends on FIRMWARE_RP1 || COMPILE_TEST
23+
default n
24+
help
25+
Driver providing control of the Raspberry Pi PIO block, as found in
26+
RP1.
27+
2028
config AD525X_DPOT
2129
tristate "Analog Devices Digital Potentiometers"
2230
depends on (I2C || SPI) && SYSFS

drivers/misc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ obj-$(CONFIG_PHANTOM) += phantom.o
2020
obj-$(CONFIG_RPMB) += rpmb-core.o
2121
obj-$(CONFIG_QCOM_COINCELL) += qcom-coincell.o
2222
obj-$(CONFIG_QCOM_FASTRPC) += fastrpc.o
23+
obj-$(CONFIG_RP1_PIO) += rp1-pio.o
2324
obj-$(CONFIG_SENSORS_BH1770) += bh1770glc.o
2425
obj-$(CONFIG_SENSORS_APDS990X) += apds990x.o
2526
obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o

drivers/misc/rp1-fw-pio.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2023 2023-2024 Raspberry Pi Ltd.
4+
*/
5+
6+
#ifndef __SOC_RP1_FIRMWARE_OPS_H__
7+
#define __SOC_RP1_FIRMWARE_OPS_H__
8+
9+
#include <linux/rp1-firmware.h>
10+
11+
#define FOURCC_PIO RP1_FOURCC("PIO ")
12+
13+
enum rp1_pio_ops {
14+
PIO_CAN_ADD_PROGRAM, // u16 num_instrs, u16 origin -> origin
15+
PIO_ADD_PROGRAM, // u16 num_instrs, u16 origin, u16 prog[] -> rc
16+
PIO_REMOVE_PROGRAM, // u16 num_instrs, u16 origin
17+
PIO_CLEAR_INSTR_MEM, // -
18+
19+
PIO_SM_CLAIM, // u16 mask -> sm
20+
PIO_SM_UNCLAIM, // u16 mask
21+
PIO_SM_IS_CLAIMED, // u16 mask -> claimed
22+
23+
PIO_SM_INIT, // u16 sm, u16 initial_pc, u32 sm_config[4]
24+
PIO_SM_SET_CONFIG, // u16 sm, u16 rsvd, u32 sm_config[4]
25+
PIO_SM_EXEC, // u16 sm, u16 instr, u8 blocking, u8 rsvd
26+
PIO_SM_CLEAR_FIFOS, // u16 sm
27+
PIO_SM_SET_CLKDIV, // u16 sm, u16 div_int, u8 div_frac, u8 rsvd
28+
PIO_SM_SET_PINS, // u16 sm, u16 rsvd, u32 values, u32 mask
29+
PIO_SM_SET_PINDIRS, // u16 sm, u16 rsvd, u32 dirs, u32 mask
30+
PIO_SM_SET_ENABLED, // u16 mask, u8 enable, u8 rsvd
31+
PIO_SM_RESTART, // u16 mask
32+
PIO_SM_CLKDIV_RESTART, // u16 mask
33+
PIO_SM_ENABLE_SYNC, // u16 mask
34+
PIO_SM_PUT, // u16 sm, u8 blocking, u8 rsvd, u32 data
35+
PIO_SM_GET, // u16 sm, u8 blocking, u8 rsvd -> u32 data
36+
PIO_SM_SET_DMACTRL, // u16 sm, u16 is_tx, u32 ctrl
37+
38+
GPIO_INIT, // u16 gpio
39+
GPIO_SET_FUNCTION, // u16 gpio, u16 fn
40+
GPIO_SET_PULLS, // u16 gpio, u8 up, u8 down
41+
GPIO_SET_OUTOVER, // u16 gpio, u16 value
42+
GPIO_SET_INOVER, // u16 gpio, u16 value
43+
GPIO_SET_OEOVER, // u16 gpio, u16 value
44+
GPIO_SET_INPUT_ENABLED, // u16 gpio, u16 value
45+
GPIO_SET_DRIVE_STRENGTH, // u16 gpio, u16 value
46+
47+
READ_HW, // src address, len -> data bytes
48+
WRITE_HW, // dst address, data
49+
50+
PIO_SM_FIFO_STATE, // u16 sm, u8 tx -> u16 level, u8 empty, u8 full
51+
PIO_SM_DRAIN_TX, // u16 sm
52+
53+
PIO_COUNT
54+
};
55+
56+
#endif

0 commit comments

Comments
 (0)