static long capella_cm3602_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int val; D("%s cmd %d\n", __func__, _IOC_NR(cmd)); switch (cmd) { case CAPELLA_CM3602_IOCTL_ENABLE: if (get_user(val, (unsigned long __user *)arg)) return -EFAULT; if (val) return capella_cm3602_enable(&the_data); else return capella_cm3602_disable(&the_data); break; case CAPELLA_CM3602_IOCTL_GET_ENABLED: return put_user(the_data.enabled, (unsigned long __user *)arg); break; default: pr_err("%s: invalid cmd %d\n", __func__, _IOC_NR(cmd)); return -EINVAL; } }
static ssize_t capella_cm3602_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count ) { ssize_t val; val = -1; sscanf(buf, "%u", &val); if (val < 0 || val > 1) return -EINVAL; /* Enable capella_cm3602*/ if (val == 1) capella_cm3602_enable(&the_data); /* Disable capella_cm3602*/ if (val == 0) capella_cm3602_disable(&the_data); return count; }