Skip to content

Commit f3ce987

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 <[email protected]> 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 <[email protected]> misc: rp1-pio: More logical probe sequence Sort the probe function initialisation into a more logical order. Signed-off-by: Phil Elwell <[email protected]> misc: rp1-pio: Minor cosmetic tweaks No functional change. Signed-off-by: Phil Elwell <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]>
1 parent 76430e3 commit f3ce987

File tree

7 files changed

+3180
-0
lines changed

7 files changed

+3180
-0
lines changed

drivers/misc/Kconfig

+8
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

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ obj-$(CONFIG_PHANTOM) += phantom.o
1919
obj-$(CONFIG_RPMB) += rpmb-core.o
2020
obj-$(CONFIG_QCOM_COINCELL) += qcom-coincell.o
2121
obj-$(CONFIG_QCOM_FASTRPC) += fastrpc.o
22+
obj-$(CONFIG_RP1_PIO) += rp1-pio.o
2223
obj-$(CONFIG_SENSORS_BH1770) += bh1770glc.o
2324
obj-$(CONFIG_SENSORS_APDS990X) += apds990x.o
2425
obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o

drivers/misc/rp1-fw-pio.h

+56
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)