master/master.c
changeset 268 4f9c149fb71f
parent 261 44a3a5833c49
child 274 b397aee6e602
equal deleted inserted replaced
267:88177083f137 268:4f9c149fb71f
    56 /*****************************************************************************/
    56 /*****************************************************************************/
    57 
    57 
    58 void ec_master_freerun(void *);
    58 void ec_master_freerun(void *);
    59 void ec_master_eoe_run(unsigned long);
    59 void ec_master_eoe_run(unsigned long);
    60 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *);
    60 ssize_t ec_show_master_attribute(struct kobject *, struct attribute *, char *);
       
    61 ssize_t ec_store_master_attribute(struct kobject *, struct attribute *,
       
    62                                   const char *, size_t);
    61 
    63 
    62 /*****************************************************************************/
    64 /*****************************************************************************/
    63 
    65 
    64 /** \cond */
    66 /** \cond */
    65 
    67 
    66 EC_SYSFS_READ_ATTR(slave_count);
    68 EC_SYSFS_READ_ATTR(slave_count);
    67 EC_SYSFS_READ_ATTR(mode);
    69 EC_SYSFS_READ_ATTR(mode);
       
    70 EC_SYSFS_READ_WRITE_ATTR(eeprom_write_enable);
    68 
    71 
    69 static struct attribute *ec_def_attrs[] = {
    72 static struct attribute *ec_def_attrs[] = {
    70     &attr_slave_count,
    73     &attr_slave_count,
    71     &attr_mode,
    74     &attr_mode,
       
    75     &attr_eeprom_write_enable,
    72     NULL,
    76     NULL,
    73 };
    77 };
    74 
    78 
    75 static struct sysfs_ops ec_sysfs_ops = {
    79 static struct sysfs_ops ec_sysfs_ops = {
    76     .show = &ec_show_master_attribute,
    80     .show = &ec_show_master_attribute,
    77     .store = NULL
    81     .store = ec_store_master_attribute
    78 };
    82 };
    79 
    83 
    80 static struct kobj_type ktype_ec_master = {
    84 static struct kobj_type ktype_ec_master = {
    81     .release = ec_master_clear,
    85     .release = ec_master_clear,
    82     .sysfs_ops = &ec_sysfs_ops,
    86     .sysfs_ops = &ec_sysfs_ops,
   242 
   246 
   243     master->request_cb = NULL;
   247     master->request_cb = NULL;
   244     master->release_cb = NULL;
   248     master->release_cb = NULL;
   245     master->cb_data = NULL;
   249     master->cb_data = NULL;
   246 
   250 
       
   251     master->eeprom_write_enable = 0;
       
   252 
   247     ec_fsm_reset(&master->fsm);
   253     ec_fsm_reset(&master->fsm);
   248 }
   254 }
   249 
   255 
   250 /*****************************************************************************/
   256 /*****************************************************************************/
   251 
   257 
   818                 return sprintf(buffer, "RUNNING\n");
   824                 return sprintf(buffer, "RUNNING\n");
   819         }
   825         }
   820     }
   826     }
   821 
   827 
   822     return 0;
   828     return 0;
       
   829 }
       
   830 
       
   831 /*****************************************************************************/
       
   832 
       
   833 /**
       
   834    Formats attribute data for SysFS write access.
       
   835    \return number of bytes processed, or negative error code
       
   836 */
       
   837 
       
   838 ssize_t ec_store_master_attribute(struct kobject *kobj, /**< slave's kobject */
       
   839                                   struct attribute *attr, /**< attribute */
       
   840                                   const char *buffer, /**< memory with data */
       
   841                                   size_t size /**< size of data to store */
       
   842                                   )
       
   843 {
       
   844     ec_master_t *master = container_of(kobj, ec_master_t, kobj);
       
   845 
       
   846     if (attr == &attr_eeprom_write_enable) {
       
   847         if (!strcmp(buffer, "1\n")) {
       
   848             master->eeprom_write_enable = 1;
       
   849             EC_INFO("Slave EEPROM writing enabled.\n");
       
   850             return size;
       
   851         }
       
   852         else if (!strcmp(buffer, "0\n")) {
       
   853             master->eeprom_write_enable = 0;
       
   854             EC_INFO("Slave EEPROM writing disabled.\n");
       
   855             return size;
       
   856         }
       
   857 
       
   858         EC_ERR("Invalid value for eeprom_write_enable!\n");
       
   859 
       
   860         if (master->eeprom_write_enable) {
       
   861             master->eeprom_write_enable = 0;
       
   862             EC_INFO("Slave EEPROM writing disabled.\n");
       
   863         }
       
   864     }
       
   865 
       
   866     return -EINVAL;
   823 }
   867 }
   824 
   868 
   825 /*****************************************************************************/
   869 /*****************************************************************************/
   826 
   870 
   827 /**
   871 /**