static void input_get_data(struct input_dev *input, int32_t *x, int32_t *y, int32_t *z, int32_t *status) { *x = input_abs_get_val(input, ABS_X); *y = input_abs_get_val(input, ABS_Y); *z = input_abs_get_val(input, ABS_Z); *status = input_abs_get_val(input, ABS_STATUS); }
static ssize_t orientation_data_show(struct device *dev, struct device_attribute *attr, char *buf) { struct input_dev *input_data = to_input_dev(dev); unsigned long flags; int x, y, z; spin_lock_irqsave(&input_data->event_lock, flags); x = input_abs_get_val(input_data, REL_X); y = input_abs_get_val(input_data, REL_Y); z = input_abs_get_val(input_data, REL_Z); spin_unlock_irqrestore(&input_data->event_lock, flags); return sprintf(buf, "%d %d %d\n", x, y, z); }
static ssize_t sensor_report_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct input_dev *input_data = to_input_dev(dev); int32_t data_x, data_y, data_z, data_rudder, data_accuracy; sscanf(buf, "%d %d %d %d %d", &data_x, &data_y, &data_z, &data_rudder, &data_accuracy); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) if( (input_data->abs[ABS_X] != data_x) || (input_data->abs[ABS_Y] != data_y) || (input_data->abs[ABS_Z] != data_z) ) { /* Orientation Accuracy Init */ input_data->abs[ABS_STATUS] = 99; } #else if( (input_abs_get_val(input_data, ABS_X) != data_x) || (input_abs_get_val(input_data, ABS_Y) != data_y) || (input_abs_get_val(input_data, ABS_Z) != data_z) ) { /* Orientation Accuracy Init */ input_abs_set_val(input_data, ABS_STATUS, 99); } #endif /* report data */ input_report_abs(input_data, ABS_X, data_x); input_report_abs(input_data, ABS_Y, data_y); input_report_abs(input_data, ABS_Z, data_z); // input_report_abs(input_data, ABS_RUDDER, data_rudder); input_report_abs(input_data, ABS_STATUS, data_accuracy); input_sync(input_data); return count; }
static ssize_t sensor_status_show(struct device *dev, struct device_attribute *attr, char *buf) { struct input_dev *input_data = to_input_dev(dev); int status; status = input_abs_get_val(input_data, ABS_STATUS); return snprintf(buf, PAGE_SIZE, "%d\n", status); }
static ssize_t sensor_data_show(struct device *dev, struct device_attribute *attr, char *buf) { struct input_dev *input_data = to_input_dev(dev); #if SENSOR_TYPE <= 4 int x, y, z; #else int x; #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) unsigned long flags; spin_lock_irqsave(&input_data->event_lock, flags); x = input_data->abs[ABS_X]; #if SENSOR_TYPE <= 4 y = input_data->abs[ABS_Y]; z = input_data->abs[ABS_Z]; #endif spin_unlock_irqrestore(&input_data->event_lock, flags); #else x = input_abs_get_val(input_data, ABS_X); #if SENSOR_TYPE <= 4 y = input_abs_get_val(input_data, ABS_Y); z = input_abs_get_val(input_data, ABS_Z); #endif #endif #if SENSOR_TYPE <= 4 return sprintf(buf, "%d %d %d\n", x, y, z); #else return sprintf(buf, "%d\n", x); #endif }
static ssize_t sensor_data_show(struct device *dev, struct device_attribute *attr, char *buf) { struct input_dev *input_data = to_input_dev(dev); #if SENSOR_TYPE <= 4 || (9 <= SENSOR_TYPE && SENSOR_TYPE <= 11) int x, y, z; #else int x; #endif x = input_abs_get_val(input_data, ABS_X); #if SENSOR_TYPE <= 4 || (9 <= SENSOR_TYPE && SENSOR_TYPE <= 11) y = input_abs_get_val(input_data, ABS_Y); z = input_abs_get_val(input_data, ABS_Z); #endif #if SENSOR_TYPE <= 4 || (9 <= SENSOR_TYPE && SENSOR_TYPE <= 11) return snprintf(buf, PAGE_SIZE, "%d %d %d\n", x, y, z); #else return snprintf(buf, PAGE_SIZE, "%d\n", x); #endif }
static ssize_t orientation_status_show(struct device *dev, struct device_attribute *attr, char *buf) { struct input_dev *input_data = to_input_dev(dev); unsigned long flags; int status; spin_lock_irqsave(&input_data->event_lock, flags); status = input_abs_get_val(input_data, REL_STATUS); spin_unlock_irqrestore(&input_data->event_lock, flags); return sprintf(buf, "%d\n", status); }
static int input_handle_abs_event(struct input_dev *dev, unsigned int code, int *pval) { struct input_mt *mt = dev->mt; bool is_mt_event; int *pold; if (code == ABS_MT_SLOT) { if (mt && *pval >= 0 && *pval < mt->num_slots) mt->slot = *pval; return INPUT_IGNORE_EVENT; } is_mt_event = input_is_mt_value(code); if (!is_mt_event) { pold = &dev->absinfo[code].value; } else if (mt) { pold = &mt->slots[mt->slot].abs[code - ABS_MT_FIRST]; } else { pold = NULL; } if (pold) { *pval = input_defuzz_abs_event(*pval, *pold, dev->absinfo[code].fuzz); if (*pold == *pval) return INPUT_IGNORE_EVENT; *pold = *pval; } if (is_mt_event && mt && mt->slot != input_abs_get_val(dev, ABS_MT_SLOT)) { input_abs_set_val(dev, ABS_MT_SLOT, mt->slot); return INPUT_PASS_TO_HANDLERS | INPUT_SLOT; } return INPUT_PASS_TO_HANDLERS; }
static ssize_t sensor_status_show(struct device *dev, struct device_attribute *attr, char *buf) { struct input_dev *input_data = to_input_dev(dev); int status; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) unsigned long flags; spin_lock_irqsave(&input_data->event_lock, flags); status = input_data->abs[ABS_STATUS]; spin_unlock_irqrestore(&input_data->event_lock, flags); #else status = input_abs_get_val(input_data, ABS_STATUS); #endif return sprintf(buf, "%d\n", status); }
/* * It so happens that the pointer that gives us the trouble * is the last field in the structure. Since we don't support * custom waveforms in uinput anyway we can just copy the whole * thing (to the compat size) and ignore the pointer. */ memcpy(&ff_up_compat.effect, &ff_up->effect, sizeof(struct ff_effect_compat)); memcpy(&ff_up_compat.old, &ff_up->old, sizeof(struct ff_effect_compat)); if (copy_to_user(buffer, &ff_up_compat, sizeof(struct uinput_ff_upload_compat))) return -EFAULT; } else { if (copy_to_user(buffer, ff_up, sizeof(struct uinput_ff_upload))) return -EFAULT; } return 0; } static int uinput_ff_upload_from_user(const char __user *buffer, struct uinput_ff_upload *ff_up) { if (INPUT_COMPAT_TEST) { struct uinput_ff_upload_compat ff_up_compat; if (copy_from_user(&ff_up_compat, buffer, sizeof(struct uinput_ff_upload_compat))) return -EFAULT; ff_up->request_id = ff_up_compat.request_id; ff_up->retval = ff_up_compat.retval; memcpy(&ff_up->effect, &ff_up_compat.effect, sizeof(struct ff_effect_compat)); memcpy(&ff_up->old, &ff_up_compat.old, sizeof(struct ff_effect_compat)); } else { if (copy_from_user(ff_up, buffer, sizeof(struct uinput_ff_upload))) return -EFAULT; } return 0; } #else static int uinput_ff_upload_to_user(char __user *buffer, const struct uinput_ff_upload *ff_up) { if (copy_to_user(buffer, ff_up, sizeof(struct uinput_ff_upload))) return -EFAULT; return 0; } static int uinput_ff_upload_from_user(const char __user *buffer, struct uinput_ff_upload *ff_up) { if (copy_from_user(ff_up, buffer, sizeof(struct uinput_ff_upload))) return -EFAULT; return 0; } #endif #define uinput_set_bit(_arg, _bit, _max) \ ({ \ int __ret = 0; \ if (udev->state == UIST_CREATED) \ __ret = -EINVAL; \ else if ((_arg) > (_max)) \ __ret = -EINVAL; \ else set_bit((_arg), udev->dev->_bit); \ __ret; \ }) #ifdef CONFIG_FEATURE_PANTECH_MDS_MTC //|| defined(FEATURE_PANTECH_STABILITY) #ifdef CONFIG_COMPAT #define BITS_PER_LONG_COMPAT (sizeof(compat_long_t) * 8) #define BITS_TO_LONGS_COMPAT(x) ((((x) - 1) / BITS_PER_LONG_COMPAT) + 1) #ifdef __BIG_ENDIAN static int bits_to_user(unsigned long *bits, unsigned int maxbit, unsigned int maxlen, void __user *p, int compat) { int len, i; if (compat) { len = BITS_TO_LONGS_COMPAT(maxbit) * sizeof(compat_long_t); if (len > maxlen) len = maxlen; for (i = 0; i < len / sizeof(compat_long_t); i++) if (copy_to_user((compat_long_t __user *) p + i, (compat_long_t *) bits + i + 1 - ((i % 2) << 1), sizeof(compat_long_t))) return -EFAULT; } else { len = BITS_TO_LONGS(maxbit) * sizeof(long); if (len > maxlen) len = maxlen; if (copy_to_user(p, bits, len)) return -EFAULT; } return len; } #else static int bits_to_user(unsigned long *bits, unsigned int maxbit, unsigned int maxlen, void __user *p, int compat) { int len = compat ? BITS_TO_LONGS_COMPAT(maxbit) * sizeof(compat_long_t) : BITS_TO_LONGS(maxbit) * sizeof(long); if (len > maxlen) len = maxlen; return copy_to_user(p, bits, len) ? -EFAULT : len; } #endif /* __BIG_ENDIAN */ #else static int bits_to_user(unsigned long *bits, unsigned int maxbit, unsigned int maxlen, void __user *p, int compat) { int len = BITS_TO_LONGS(maxbit) * sizeof(long); if (len > maxlen) len = maxlen; return copy_to_user(p, bits, len) ? -EFAULT : len; } #endif /* CONFIG_COMPAT */ static int str_to_user(const char *str, unsigned int maxlen, void __user *p) { int len; if (!str) return -ENOENT; len = strlen(str) + 1; if (len > maxlen) len = maxlen; return copy_to_user(p, str, len) ? -EFAULT : len; } #define OLD_KEY_MAX 0x1ff static int handle_eviocgbit(struct input_dev *dev, unsigned int cmd, void __user *p, int compat_mode) { unsigned long *bits; int len; switch (_IOC_NR(cmd) & EV_MAX) { case 0: bits = dev->evbit; len = EV_MAX; break; case EV_KEY: bits = dev->keybit; len = KEY_MAX; break; case EV_REL: bits = dev->relbit; len = REL_MAX; break; case EV_ABS: bits = dev->absbit; len = ABS_MAX; break; case EV_MSC: bits = dev->mscbit; len = MSC_MAX; break; case EV_LED: bits = dev->ledbit; len = LED_MAX; break; case EV_SND: bits = dev->sndbit; len = SND_MAX; break; case EV_FF: bits = dev->ffbit; len = FF_MAX; break; case EV_SW: bits = dev->swbit; len = SW_MAX; break; default: return -EINVAL; } if ((_IOC_NR(cmd) & EV_MAX) == EV_KEY && _IOC_SIZE(cmd) == OLD_KEY_MAX) { len = OLD_KEY_MAX; } return bits_to_user(bits, len, _IOC_SIZE(cmd), p, compat_mode); } #undef OLD_KEY_MAX #endif/*CONFIG_FEATURE_PANTECH_MDS_MTC || FEATURE_PANTECH_STABILITY*/ static long uinput_ioctl_handler(struct file *file, unsigned int cmd, unsigned long arg, void __user *p) { int retval; struct uinput_device *udev = file->private_data; struct uinput_ff_upload ff_up; struct uinput_ff_erase ff_erase; struct uinput_request *req; char *phys; retval = mutex_lock_interruptible(&udev->mutex); if (retval) return retval; if (!udev->dev) { retval = uinput_allocate_device(udev); if (retval) goto out; } switch (cmd) { case UI_DEV_CREATE: retval = uinput_create_device(udev); break; case UI_DEV_DESTROY: uinput_destroy_device(udev); break; #ifdef CONFIG_FEATURE_PANTECH_MDS_MTC //|| defined(FEATURE_PANTECH_STABILITY) case EVIOCGVERSION: if (udev->state != UIST_CREATED) retval = -ENODEV; else put_user(EV_VERSION, (int __user *)p); break; case EVIOCGID: if (udev->state != UIST_CREATED) retval = -ENODEV; else if (copy_to_user(p, &udev->dev->id, sizeof(struct input_id))) retval = -EFAULT; break; #endif/*CONFIG_FEATURE_PANTECH_MDS_MTC || FEATURE_PANTECH_STABILITY*/ case UI_SET_EVBIT: retval = uinput_set_bit(arg, evbit, EV_MAX); break; case UI_SET_KEYBIT: retval = uinput_set_bit(arg, keybit, KEY_MAX); break; case UI_SET_RELBIT: retval = uinput_set_bit(arg, relbit, REL_MAX); break; case UI_SET_ABSBIT: retval = uinput_set_bit(arg, absbit, ABS_MAX); break; case UI_SET_MSCBIT: retval = uinput_set_bit(arg, mscbit, MSC_MAX); break; case UI_SET_LEDBIT: retval = uinput_set_bit(arg, ledbit, LED_MAX); break; case UI_SET_SNDBIT: retval = uinput_set_bit(arg, sndbit, SND_MAX); break; case UI_SET_FFBIT: retval = uinput_set_bit(arg, ffbit, FF_MAX); break; case UI_SET_SWBIT: retval = uinput_set_bit(arg, swbit, SW_MAX); break; case UI_SET_PROPBIT: retval = uinput_set_bit(arg, propbit, INPUT_PROP_MAX); break; case UI_SET_PHYS: if (udev->state == UIST_CREATED) { retval = -EINVAL; goto out; } phys = strndup_user(p, 1024); if (IS_ERR(phys)) { retval = PTR_ERR(phys); goto out; } kfree(udev->dev->phys); udev->dev->phys = phys; break; case UI_BEGIN_FF_UPLOAD: retval = uinput_ff_upload_from_user(p, &ff_up); if (retval) break; req = uinput_request_find(udev, ff_up.request_id); if (!req || req->code != UI_FF_UPLOAD || !req->u.upload.effect) { retval = -EINVAL; break; } ff_up.retval = 0; ff_up.effect = *req->u.upload.effect; if (req->u.upload.old) ff_up.old = *req->u.upload.old; else memset(&ff_up.old, 0, sizeof(struct ff_effect)); retval = uinput_ff_upload_to_user(p, &ff_up); break; case UI_BEGIN_FF_ERASE: if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) { retval = -EFAULT; break; } req = uinput_request_find(udev, ff_erase.request_id); if (!req || req->code != UI_FF_ERASE) { retval = -EINVAL; break; } ff_erase.retval = 0; ff_erase.effect_id = req->u.effect_id; if (copy_to_user(p, &ff_erase, sizeof(ff_erase))) { retval = -EFAULT; break; } break; case UI_END_FF_UPLOAD: retval = uinput_ff_upload_from_user(p, &ff_up); if (retval) break; req = uinput_request_find(udev, ff_up.request_id); if (!req || req->code != UI_FF_UPLOAD || !req->u.upload.effect) { retval = -EINVAL; break; } req->retval = ff_up.retval; uinput_request_done(udev, req); break; case UI_END_FF_ERASE: if (copy_from_user(&ff_erase, p, sizeof(ff_erase))) { retval = -EFAULT; break; } req = uinput_request_find(udev, ff_erase.request_id); if (!req || req->code != UI_FF_ERASE) { retval = -EINVAL; break; } req->retval = ff_erase.retval; uinput_request_done(udev, req); break; default: #ifdef CONFIG_FEATURE_PANTECH_MDS_MTC // || defined(FEATURE_PANTECH_STABILITY) { if (udev->state != UIST_CREATED){ retval = -ENODEV; break; } if (_IOC_DIR(cmd) == _IOC_READ) { if ((_IOC_NR(cmd) & ~EV_MAX) == _IOC_NR(EVIOCGBIT(0, 0))) handle_eviocgbit(udev->dev, cmd, p, 0); if (_IOC_NR(cmd) == _IOC_NR(EVIOCGKEY(0))) bits_to_user(udev->dev->key, KEY_MAX, _IOC_SIZE(cmd), p, 0); if (_IOC_NR(cmd) == _IOC_NR(EVIOCGLED(0))) bits_to_user(udev->dev->led, LED_MAX, _IOC_SIZE(cmd), p, 0); if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSND(0))) bits_to_user(udev->dev->snd, SND_MAX, _IOC_SIZE(cmd), p, 0); if (_IOC_NR(cmd) == _IOC_NR(EVIOCGSW(0))) bits_to_user(udev->dev->sw, SW_MAX, _IOC_SIZE(cmd), p, 0); if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) str_to_user(udev->dev->name, _IOC_SIZE(cmd), p); if (_IOC_NR(cmd) == _IOC_NR(EVIOCGPHYS(0))) str_to_user(udev->dev->phys, _IOC_SIZE(cmd), p); if (_IOC_NR(cmd) == _IOC_NR(EVIOCGUNIQ(0))) str_to_user(udev->dev->uniq, _IOC_SIZE(cmd), p); if ((_IOC_NR(cmd) & ~ABS_MAX) == _IOC_NR(EVIOCGABS(0))) { int t; struct input_absinfo abs; t = _IOC_NR(cmd) & ABS_MAX; abs.value = input_abs_get_val(udev->dev,t); abs.minimum = input_abs_get_min(udev->dev,t); abs.maximum = input_abs_get_max(udev->dev,t); abs.fuzz = input_abs_get_fuzz(udev->dev,t); abs.flat = input_abs_get_flat(udev->dev,t); /* abs.value = udev->dev->abs[t]; abs.minimum = udev->dev->absmin[t]; abs.maximum = udev->dev->absmax[t]; abs.fuzz = udev->dev->absfuzz[t]; abs.flat = udev->dev->absflat[t]; */ if (copy_to_user(p, &abs, sizeof(struct input_absinfo))) retval= -EFAULT; } } } #else retval = -EINVAL; #endif/*CONFIG_FEATURE_PANTECH_MDS_MTC || FEATURE_PANTECH_STABILITY*/ } out: mutex_unlock(&udev->mutex); return retval; }