EEPROM write enable SysFS entry.
authorFlorian Pose <fp@igh-essen.com>
Fri, 02 Jun 2006 12:01:47 +0000
changeset 268 4f9c149fb71f
parent 267 88177083f137
child 269 a03be9a6fed6
EEPROM write enable SysFS entry.
master/master.c
master/master.h
--- a/master/master.c	Fri Jun 02 09:02:18 2006 +0000
+++ b/master/master.c	Fri Jun 02 12:01:47 2006 +0000
@@ -58,6 +58,8 @@
 void ec_master_freerun(void *);
 void ec_master_eoe_run(unsigned long);
 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *);
+ssize_t ec_store_master_attribute(struct kobject *, struct attribute *,
+                                  const char *, size_t);
 
 /*****************************************************************************/
 
@@ -65,16 +67,18 @@
 
 EC_SYSFS_READ_ATTR(slave_count);
 EC_SYSFS_READ_ATTR(mode);
+EC_SYSFS_READ_WRITE_ATTR(eeprom_write_enable);
 
 static struct attribute *ec_def_attrs[] = {
     &attr_slave_count,
     &attr_mode,
+    &attr_eeprom_write_enable,
     NULL,
 };
 
 static struct sysfs_ops ec_sysfs_ops = {
     .show = &ec_show_master_attribute,
-    .store = NULL
+    .store = ec_store_master_attribute
 };
 
 static struct kobj_type ktype_ec_master = {
@@ -244,6 +248,8 @@
     master->release_cb = NULL;
     master->cb_data = NULL;
 
+    master->eeprom_write_enable = 0;
+
     ec_fsm_reset(&master->fsm);
 }
 
@@ -825,6 +831,44 @@
 /*****************************************************************************/
 
 /**
+   Formats attribute data for SysFS write access.
+   \return number of bytes processed, or negative error code
+*/
+
+ssize_t ec_store_master_attribute(struct kobject *kobj, /**< slave's kobject */
+                                  struct attribute *attr, /**< attribute */
+                                  const char *buffer, /**< memory with data */
+                                  size_t size /**< size of data to store */
+                                  )
+{
+    ec_master_t *master = container_of(kobj, ec_master_t, kobj);
+
+    if (attr == &attr_eeprom_write_enable) {
+        if (!strcmp(buffer, "1\n")) {
+            master->eeprom_write_enable = 1;
+            EC_INFO("Slave EEPROM writing enabled.\n");
+            return size;
+        }
+        else if (!strcmp(buffer, "0\n")) {
+            master->eeprom_write_enable = 0;
+            EC_INFO("Slave EEPROM writing disabled.\n");
+            return size;
+        }
+
+        EC_ERR("Invalid value for eeprom_write_enable!\n");
+
+        if (master->eeprom_write_enable) {
+            master->eeprom_write_enable = 0;
+            EC_INFO("Slave EEPROM writing disabled.\n");
+        }
+    }
+
+    return -EINVAL;
+}
+
+/*****************************************************************************/
+
+/**
    Starts Ethernet-over-EtherCAT processing for all EoE-capable slaves.
 */
 
--- a/master/master.h	Fri Jun 02 09:02:18 2006 +0000
+++ b/master/master.h	Fri Jun 02 12:01:47 2006 +0000
@@ -122,6 +122,8 @@
     int (*request_cb)(void *); /**< lock request callback */
     void (*release_cb)(void *); /**< lock release callback */
     void *cb_data; /**< data parameter of locking callbacks */
+
+    uint8_t eeprom_write_enable; /**< allow write operations to EEPROMs */
 };
 
 /*****************************************************************************/