Skip to content

Commit 2a820ca

Browse files
brglandersson
authored andcommitted
drivers: add support for pic32cx
PIC32CX is a newer debug board used on automotive platforms like sa8797p. It uses human-readable commands over serial but speaks a different dialect than alpaca. Add a new driver to support it and extend available config options. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent b6c766d commit 2a820ca

5 files changed

Lines changed: 98 additions & 0 deletions

File tree

device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ extern const struct control_ops local_gpio_ops;
103103
extern const struct control_ops external_ops;
104104
extern const struct control_ops qcomlt_dbg_ops;
105105
extern const struct control_ops laurent_ops;
106+
extern const struct control_ops pic32cx_ops;
106107

107108
extern const struct console_ops conmux_console_ops;
108109
extern const struct console_ops console_ops;

device_parser.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ static void parse_board(struct device_parser *dp)
172172
} else if (!strcmp(key, "alpaca")) {
173173
dev->control_dev = strdup(value);
174174
set_control_ops(dev, &alpaca_ops);
175+
} else if (!strcmp(key, "pic32cx")) {
176+
dev->control_dev = strdup(value);
177+
set_control_ops(dev, &pic32cx_ops);
175178
} else if (!strcmp(key, "external")) {
176179
dev->control_dev = strdup(value);
177180
set_control_ops(dev, &external_ops);

drivers/pic32cx.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2026 Qualcomm Technologies, Inc. and/or its subsidiaries
3+
* All rights reserved.
4+
*
5+
* SPDX-License-Identifier: BSD-3-Clause
6+
*/
7+
8+
#include <err.h>
9+
#include <stdarg.h>
10+
#include <stdio.h>
11+
#include <string.h>
12+
#include <stdlib.h>
13+
#include <sys/types.h>
14+
#include <termios.h>
15+
#include <unistd.h>
16+
17+
#include "device.h"
18+
#include "tty.h"
19+
20+
struct pic32cx {
21+
int fd;
22+
struct termios tios;
23+
bool fastboot_pressed;
24+
};
25+
26+
static void pic32cx_device_write(struct pic32cx *pic32cx, const char *fmt, ...)
27+
{
28+
char buf[32];
29+
va_list va;
30+
int count;
31+
va_start(va, fmt);
32+
count = vsnprintf(buf, sizeof(buf), fmt, va);
33+
va_end(va);
34+
35+
write(pic32cx->fd, buf, count);
36+
}
37+
38+
static void pic32cx_device_power(struct pic32cx *pic32cx, int on)
39+
{
40+
pic32cx_device_write(pic32cx, "PWR_OFF %d\r", !on);
41+
}
42+
43+
static void *pic32cx_open(struct device *dev)
44+
{
45+
struct pic32cx *pic32cx;
46+
47+
dev->has_power_key = true;
48+
49+
pic32cx = calloc(1, sizeof(*pic32cx));
50+
51+
pic32cx->fd = tty_open(dev->control_dev, &pic32cx->tios);
52+
if (pic32cx->fd < 0)
53+
err(1, "failed to open %s", dev->control_dev);
54+
55+
pic32cx_device_power(pic32cx, 1);
56+
57+
sleep(5);
58+
59+
return pic32cx;
60+
}
61+
62+
static int pic32cx_power(struct device *dev, bool on)
63+
{
64+
pic32cx_device_power(dev->cdb, on);
65+
66+
return 0;
67+
}
68+
69+
static void pic32cx_key(struct device *dev, int key, bool asserted)
70+
{
71+
struct pic32cx *pic32cx = dev->cdb;
72+
73+
switch (key) {
74+
case DEVICE_KEY_FASTBOOT:
75+
if (asserted)
76+
pic32cx->fastboot_pressed = true;
77+
if (!asserted && pic32cx->fastboot_pressed) {
78+
pic32cx_device_write(pic32cx, "MD_FASTBOOT\r");
79+
pic32cx->fastboot_pressed = false;
80+
}
81+
break;
82+
}
83+
}
84+
85+
const struct control_ops pic32cx_ops = {
86+
.open = pic32cx_open,
87+
.power = pic32cx_power,
88+
.key = pic32cx_key,
89+
};

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ drivers_srcs = ['drivers/alpaca.c',
7272
'drivers/ftdi-gpio.c',
7373
'drivers/laurent.c',
7474
'drivers/local-gpio.c',
75+
'drivers/pic32cx.c',
7576
'drivers/qcomlt_dbg.c',
7677
]
7778

schema.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ properties:
8585
description: Alpaca board control device path
8686
$ref: "#/$defs/device_path"
8787

88+
pic32cx:
89+
description: PIC32CX board control device path
90+
$ref: "#/$defs/device_path"
91+
8892
users:
8993
description: User access allowance for the board
9094
type: array

0 commit comments

Comments
 (0)