Skip to contentSkip to conversation

ptp: ocp: add I2C ISP support for ADVA TimeCard CPLD

PATCH Superseded Sagi Maimon 2 participants 2 messages Jun 28 – Jun 29

Subsystems (4)

v2 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ptp: ocp: add I2C ISP support for ADVA TimeCard CPLD

The ADVA TimeCard programs its on-board CPLD (Lattice MachXO3) via I2C using in-system programming (ISP).

The CPLD resides on a secondary I2C bus controlled by the embedded MicroBlaze. To allow programming, the driver must take ownership of this bus and expose it to userspace.

Add support to:
- enable the i2c-dev interface to expose /dev/i2c-N
- provide sysfs control over the secondary I2C bus

---
Address comments from:
- Andrew Lunn: https://www.spinics.net/lists/netdev/msg1200997.html

Changes since v1:
- Add reasoning to the commit message

 drivers/ptp/ptp_ocp.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/ptp/ptp_ocp.c +30 -0
index 35e911f1ad78..1b4ccb4feca5 100644
@@ -4224,6 +4224,34 @@ static const struct ocp_attr_group art_timecard_groups[] = {
 	{ },
 };
 
+static ssize_t
+i2c_bus_ctrl_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct ptp_ocp *bp = dev_get_drvdata(dev);
+
+	if (!bp->pps_select)
+		return -ENODEV;
+	return sysfs_emit(buf, "0x%08x\n",
+			  ioread32(&bp->pps_select->__pad1));
+}
+
+static ssize_t
+i2c_bus_ctrl_store(struct device *dev, struct device_attribute *attr,
+		   const char *buf, size_t count)
+{
+	struct ptp_ocp *bp = dev_get_drvdata(dev);
+	u32 val;
+
+	if (!bp->pps_select)
+		return -ENODEV;
+	if (kstrtou32(buf, 0, &val))
+		return -EINVAL;
+	iowrite32(val, &bp->pps_select->__pad1);
+	return count;
+}
+
+static DEVICE_ATTR_RW(i2c_bus_ctrl);
+
 static struct attribute *adva_timecard_attrs[] = {
 	&dev_attr_serialnum.attr,
 	&dev_attr_gnss_sync.attr,
@@ -4272,6 +4300,7 @@ static struct attribute *adva_timecard_x1_attrs[] = {
 	&dev_attr_ts_window_adjust.attr,
 	&dev_attr_utc_tai_offset.attr,
 	&dev_attr_tod_correction.attr,
+	&dev_attr_i2c_bus_ctrl.attr,
 	NULL,
 };
 
@@ -5235,6 +5264,7 @@ ptp_ocp_init(void)
 	const char *what;
 	int err;
 
+	request_module("i2c-dev");
 	ptp_ocp_debugfs_init();
 
 	what = "timecard class";
Signature · 1 line
2.47.0
maintainer
#1 lore raw
Quoted 7 lines · Sagi Maimon

The ADVA TimeCard programs its on-board CPLD (Lattice MachXO3) via I2C using in-system programming (ISP).

The CPLD resides on a secondary I2C bus controlled by the embedded MicroBlaze. To allow programming, the driver must take ownership of this bus and expose it to userspace.

Quoted 8 lines

Add support to:
- enable the i2c-dev interface to expose /dev/i2c-N
- provide sysfs control over the secondary I2C bus

---
Address comments from:
- Andrew Lunn: https://www.spinics.net/lists/netdev/msg1200997.html

I don't see anything regarding module_request() part.
It looks like you want to expose raw I2C access for user-space software to do direct writes to the HW, which is not modeled as a device in kernel. Exposure of /dev/i2c bus affects other Time Cards where we tried to hide to avoid direct writes to EEPROM areas.

If you need some addresses of i2c bus to be accessible, it's better to implement these accesses as sysfs or debugfs attributes and expose them for ADVA cards.