Skip to content

Commit c205d53

Browse files
jlemondavem330
authored andcommitted
ptp: ocp: Add firmware capability bits for feature gating
Add the ability to group sysfs nodes behind a firmware feature check. This way non-present sysfs attributes are omitted on older firmware, which does not have newer features. This will be used in the upcoming patches which adds more features to the timecard. Signed-off-by: Jonathan Lemon <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent cd09193 commit c205d53

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

drivers/ptp/ptp_ocp.c

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ struct ptp_ocp_sma_connector {
218218
bool disabled;
219219
};
220220

221+
struct ocp_attr_group {
222+
u64 cap;
223+
const struct attribute_group *group;
224+
};
225+
226+
#define OCP_CAP_BASIC BIT(0)
227+
221228
#define OCP_BOARD_ID_LEN 13
222229
#define OCP_SERIAL_LEN 6
223230

@@ -248,6 +255,7 @@ struct ptp_ocp {
248255
struct platform_device *spi_flash;
249256
struct clk_hw *i2c_clk;
250257
struct timer_list watchdog;
258+
const struct ocp_attr_group *attr_tbl;
251259
const struct ptp_ocp_eeprom_map *eeprom_map;
252260
struct dentry *debug_root;
253261
time64_t gnss_lost;
@@ -265,6 +273,7 @@ struct ptp_ocp {
265273
int flash_start;
266274
u32 utc_tai_offset;
267275
u32 ts_window_adjust;
276+
u64 fw_cap;
268277
struct ptp_ocp_sma_connector sma[4];
269278
};
270279

@@ -290,6 +299,8 @@ static int ptp_ocp_fb_board_init(struct ptp_ocp *bp, struct ocp_resource *r);
290299
static irqreturn_t ptp_ocp_ts_irq(int irq, void *priv);
291300
static int ptp_ocp_ts_enable(void *priv, u32 req, bool enable);
292301

302+
static const struct ocp_attr_group fb_timecard_groups[];
303+
293304
struct ptp_ocp_eeprom_map {
294305
u16 off;
295306
u16 len;
@@ -1526,6 +1537,8 @@ ptp_ocp_fb_board_init(struct ptp_ocp *bp, struct ocp_resource *r)
15261537
bp->flash_start = 1024 * 4096;
15271538
bp->eeprom_map = fb_eeprom_map;
15281539
bp->fw_version = ioread32(&bp->image->version);
1540+
bp->attr_tbl = fb_timecard_groups;
1541+
bp->fw_cap = OCP_CAP_BASIC;
15291542

15301543
ptp_ocp_tod_init(bp);
15311544
ptp_ocp_nmea_out_init(bp);
@@ -2167,7 +2180,7 @@ tod_correction_store(struct device *dev, struct device_attribute *attr,
21672180
}
21682181
static DEVICE_ATTR_RW(tod_correction);
21692182

2170-
static struct attribute *timecard_attrs[] = {
2183+
static struct attribute *fb_timecard_attrs[] = {
21712184
&dev_attr_serialnum.attr,
21722185
&dev_attr_gnss_sync.attr,
21732186
&dev_attr_clock_source.attr,
@@ -2186,7 +2199,13 @@ static struct attribute *timecard_attrs[] = {
21862199
&dev_attr_tod_correction.attr,
21872200
NULL,
21882201
};
2189-
ATTRIBUTE_GROUPS(timecard);
2202+
static const struct attribute_group fb_timecard_group = {
2203+
.attrs = fb_timecard_attrs,
2204+
};
2205+
static const struct ocp_attr_group fb_timecard_groups[] = {
2206+
{ .cap = OCP_CAP_BASIC, .group = &fb_timecard_group },
2207+
{ },
2208+
};
21902209

21912210
static void
21922211
gpio_input_map(char *buf, struct ptp_ocp *bp, u16 map[][2], u16 bit,
@@ -2605,6 +2624,7 @@ ptp_ocp_complete(struct ptp_ocp *bp)
26052624
{
26062625
struct pps_device *pps;
26072626
char buf[32];
2627+
int i, err;
26082628

26092629
if (bp->gnss_port != -1) {
26102630
sprintf(buf, "ttyS%d", bp->gnss_port);
@@ -2629,8 +2649,13 @@ ptp_ocp_complete(struct ptp_ocp *bp)
26292649
if (pps)
26302650
ptp_ocp_symlink(bp, pps->dev, "pps");
26312651

2632-
if (device_add_groups(&bp->dev, timecard_groups))
2633-
pr_err("device add groups failed\n");
2652+
for (i = 0; bp->attr_tbl[i].cap; i++) {
2653+
if (!(bp->attr_tbl[i].cap & bp->fw_cap))
2654+
continue;
2655+
err = sysfs_create_group(&bp->dev.kobj, bp->attr_tbl[i].group);
2656+
if (err)
2657+
return err;
2658+
}
26342659

26352660
ptp_ocp_debugfs_add_device(bp);
26362661

@@ -2703,12 +2728,15 @@ static void
27032728
ptp_ocp_detach_sysfs(struct ptp_ocp *bp)
27042729
{
27052730
struct device *dev = &bp->dev;
2731+
int i;
27062732

27072733
sysfs_remove_link(&dev->kobj, "ttyGNSS");
27082734
sysfs_remove_link(&dev->kobj, "ttyMAC");
27092735
sysfs_remove_link(&dev->kobj, "ptp");
27102736
sysfs_remove_link(&dev->kobj, "pps");
2711-
device_remove_groups(dev, timecard_groups);
2737+
if (bp->attr_tbl)
2738+
for (i = 0; bp->attr_tbl[i].cap; i++)
2739+
sysfs_remove_group(&dev->kobj, bp->attr_tbl[i].group);
27122740
}
27132741

27142742
static void

0 commit comments

Comments
 (0)