Commit 20951baa authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Vojtech Pavlik

Input: fix identation in PID driver.

Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Signed-off-by: default avatarVojtech Pavlik <vojtech@suse.cz>
parent 21da1ba3
...@@ -48,65 +48,63 @@ ...@@ -48,65 +48,63 @@
/* Called when a transfer is completed */ /* Called when a transfer is completed */
static void hid_pid_ctrl_out(struct urb *u, struct pt_regs *regs) static void hid_pid_ctrl_out(struct urb *u, struct pt_regs *regs)
{ {
dev_dbg(&u->dev->dev, "hid_pid_ctrl_out - Transfer Completed\n"); dev_dbg(&u->dev->dev, "hid_pid_ctrl_out - Transfer Completed\n");
} }
static void hid_pid_exit(struct hid_device* hid) static void hid_pid_exit(struct hid_device *hid)
{ {
struct hid_ff_pid *private = hid->ff_private; struct hid_ff_pid *private = hid->ff_private;
if (private->urbffout) { if (private->urbffout) {
usb_kill_urb(private->urbffout); usb_kill_urb(private->urbffout);
usb_free_urb(private->urbffout); usb_free_urb(private->urbffout);
} }
} }
static int pid_upload_periodic(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update) { static int pid_upload_periodic(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
dev_info(&pid->hid->dev->dev, "requested periodic force upload\n"); {
return 0; dev_info(&pid->hid->dev->dev, "requested periodic force upload\n");
return 0;
} }
static int pid_upload_constant(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update) { static int pid_upload_constant(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
dev_info(&pid->hid->dev->dev, "requested constant force upload\n"); {
return 0; dev_info(&pid->hid->dev->dev, "requested constant force upload\n");
return 0;
} }
static int pid_upload_condition(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update) { static int pid_upload_condition(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
dev_info(&pid->hid->dev->dev, "requested Condition force upload\n"); {
return 0; dev_info(&pid->hid->dev->dev, "requested Condition force upload\n");
return 0;
} }
static int pid_upload_ramp(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update) { static int pid_upload_ramp(struct hid_ff_pid *pid, struct ff_effect *effect, int is_update)
dev_info(&pid->hid->dev->dev, "request ramp force upload\n"); {
return 0; dev_info(&pid->hid->dev->dev, "request ramp force upload\n");
return 0;
} }
static int hid_pid_event(struct hid_device *hid, struct input_dev *input, static int hid_pid_event(struct hid_device *hid, struct input_dev *input,
unsigned int type, unsigned int code, int value) unsigned int type, unsigned int code, int value)
{ {
dev_dbg(&hid->dev->dev, "PID event received: type=%d,code=%d,value=%d.\n", type, code, value); dev_dbg(&hid->dev->dev, "PID event received: type=%d,code=%d,value=%d.\n", type, code, value);
if (type != EV_FF)
return -1;
if (type != EV_FF)
return -1;
return 0; return 0;
} }
/* Lock must be held by caller */ /* Lock must be held by caller */
static void hid_pid_ctrl_playback(struct hid_device *hid, static void hid_pid_ctrl_playback(struct hid_device *hid, struct hid_pid_effect *effect, int play)
struct hid_pid_effect *effect, int play)
{ {
if (play) { if (play)
set_bit(FF_PID_FLAGS_PLAYING, &effect->flags); set_bit(FF_PID_FLAGS_PLAYING, &effect->flags);
else
} else {
clear_bit(FF_PID_FLAGS_PLAYING, &effect->flags); clear_bit(FF_PID_FLAGS_PLAYING, &effect->flags);
}
} }
static int hid_pid_erase(struct input_dev *dev, int id) static int hid_pid_erase(struct input_dev *dev, int id)
{ {
struct hid_device *hid = dev->private; struct hid_device *hid = dev->private;
...@@ -139,7 +137,7 @@ static int hid_pid_erase(struct input_dev *dev, int id) ...@@ -139,7 +137,7 @@ static int hid_pid_erase(struct input_dev *dev, int id)
pid->effects[id].flags = 0; pid->effects[id].flags = 0;
spin_unlock_irqrestore(&pid->lock, flags); spin_unlock_irqrestore(&pid->lock, flags);
return ret; return 0;
} }
/* Erase all effects this process owns */ /* Erase all effects this process owns */
...@@ -150,31 +148,32 @@ static int hid_pid_flush(struct input_dev *dev, struct file *file) ...@@ -150,31 +148,32 @@ static int hid_pid_flush(struct input_dev *dev, struct file *file)
int i; int i;
/*NOTE: no need to lock here. The only times EFFECT_USED is /*NOTE: no need to lock here. The only times EFFECT_USED is
modified is when effects are uploaded or when an effect is modified is when effects are uploaded or when an effect is
erased. But a process cannot close its dev/input/eventX fd erased. But a process cannot close its dev/input/eventX fd
and perform ioctls on the same fd all at the same time */ and perform ioctls on the same fd all at the same time */
for (i=0; i<dev->ff_effects_max; ++i) /*FIXME: multiple threads, anyone? */
if ( current->pid == pid->effects[i].owner for (i = 0; i < dev->ff_effects_max; ++i)
&& test_bit(FF_PID_FLAGS_USED, &pid->effects[i].flags)) if (current->pid == pid->effects[i].owner
&& test_bit(FF_PID_FLAGS_USED, &pid->effects[i].flags))
if (hid_pid_erase(dev, i)) if (hid_pid_erase(dev, i))
dev_warn(&hid->dev->dev, "erase effect %d failed", i); dev_warn(&hid->dev->dev, "erase effect %d failed", i);
return 0; return 0;
} }
static int hid_pid_upload_effect(struct input_dev *dev, static int hid_pid_upload_effect(struct input_dev *dev,
struct ff_effect *effect) struct ff_effect *effect)
{ {
struct hid_ff_pid* pid_private = (struct hid_ff_pid*)(dev->private); struct hid_ff_pid *pid_private = (struct hid_ff_pid *)(dev->private);
int ret; int ret;
int is_update; int is_update;
unsigned long flags = 0; unsigned long flags;
dev_dbg(&pid_private->hid->dev->dev, "upload effect called: effect_type=%x\n",effect->type); dev_dbg(&pid_private->hid->dev->dev, "upload effect called: effect_type=%x\n", effect->type);
/* Check this effect type is supported by this device */ /* Check this effect type is supported by this device */
if (!test_bit(effect->type, dev->ffbit)) { if (!test_bit(effect->type, dev->ffbit)) {
dev_dbg(&pid_private->hid->dev->dev, "invalid kind of effect requested.\n"); dev_dbg(&pid_private->hid->dev->dev,
"invalid kind of effect requested.\n");
return -EINVAL; return -EINVAL;
} }
...@@ -182,31 +181,30 @@ static int hid_pid_upload_effect(struct input_dev *dev, ...@@ -182,31 +181,30 @@ static int hid_pid_upload_effect(struct input_dev *dev,
* If we want to create a new effect, get a free id * If we want to create a new effect, get a free id
*/ */
if (effect->id == -1) { if (effect->id == -1) {
int id=0; int id = 0;
// Spinlock so we don`t get a race condition when choosing IDs // Spinlock so we don`t get a race condition when choosing IDs
spin_lock_irqsave(&pid_private->lock, flags); spin_lock_irqsave(&pid_private->lock, flags);
while(id < FF_EFFECTS_MAX) while (id < FF_EFFECTS_MAX)
if (!test_and_set_bit(FF_PID_FLAGS_USED, &pid_private->effects[id++].flags)) if (!test_and_set_bit(FF_PID_FLAGS_USED, &pid_private->effects[id++].flags))
break; break;
if ( id == FF_EFFECTS_MAX) { if (id == FF_EFFECTS_MAX) {
spin_unlock_irqrestore(&pid_private->lock,flags); spin_unlock_irqrestore(&pid_private->lock, flags);
// TEMP - We need to get ff_effects_max correctly first: || id >= dev->ff_effects_max) { // TEMP - We need to get ff_effects_max correctly first: || id >= dev->ff_effects_max) {
dev_dbg(&pid_private->hid->dev->dev, "Not enough device memory\n"); dev_dbg(&pid_private->hid->dev->dev, "Not enough device memory\n");
return -ENOMEM; return -ENOMEM;
} }
effect->id = id; effect->id = id;
dev_dbg(&pid_private->hid->dev->dev, "effect ID is %d\n.",id); dev_dbg(&pid_private->hid->dev->dev, "effect ID is %d\n.", id);
pid_private->effects[id].owner = current->pid; pid_private->effects[id].owner = current->pid;
pid_private->effects[id].flags = (1<<FF_PID_FLAGS_USED); pid_private->effects[id].flags = (1 << FF_PID_FLAGS_USED);
spin_unlock_irqrestore(&pid_private->lock,flags); spin_unlock_irqrestore(&pid_private->lock, flags);
is_update = FF_PID_FALSE; is_update = FF_PID_FALSE;
} } else {
else {
/* We want to update an effect */ /* We want to update an effect */
if (!CHECK_OWNERSHIP(effect->id, pid_private)) if (!CHECK_OWNERSHIP(effect->id, pid_private))
return -EACCES; return -EACCES;
...@@ -216,9 +214,8 @@ static int hid_pid_upload_effect(struct input_dev *dev, ...@@ -216,9 +214,8 @@ static int hid_pid_upload_effect(struct input_dev *dev,
return -EINVAL; return -EINVAL;
/* Check the effect is not already being updated */ /* Check the effect is not already being updated */
if (test_bit(FF_PID_FLAGS_UPDATING, &pid_private->effects[effect->id].flags)) { if (test_bit(FF_PID_FLAGS_UPDATING, &pid_private->effects[effect->id].flags))
return -EAGAIN; return -EAGAIN;
}
is_update = FF_PID_TRUE; is_update = FF_PID_TRUE;
} }
...@@ -227,28 +224,30 @@ static int hid_pid_upload_effect(struct input_dev *dev, ...@@ -227,28 +224,30 @@ static int hid_pid_upload_effect(struct input_dev *dev,
* Upload the effect * Upload the effect
*/ */
switch (effect->type) { switch (effect->type) {
case FF_PERIODIC: case FF_PERIODIC:
ret = pid_upload_periodic(pid_private, effect, is_update); ret = pid_upload_periodic(pid_private, effect, is_update);
break; break;
case FF_CONSTANT: case FF_CONSTANT:
ret = pid_upload_constant(pid_private, effect, is_update); ret = pid_upload_constant(pid_private, effect, is_update);
break; break;
case FF_SPRING: case FF_SPRING:
case FF_FRICTION: case FF_FRICTION:
case FF_DAMPER: case FF_DAMPER:
case FF_INERTIA: case FF_INERTIA:
ret = pid_upload_condition(pid_private, effect, is_update); ret = pid_upload_condition(pid_private, effect, is_update);
break; break;
case FF_RAMP: case FF_RAMP:
ret = pid_upload_ramp(pid_private, effect, is_update); ret = pid_upload_ramp(pid_private, effect, is_update);
break; break;
default: default:
dev_dbg(&pid_private->hid->dev->dev, "invalid type of effect requested - %x.\n", effect->type); dev_dbg(&pid_private->hid->dev->dev,
return -EINVAL; "invalid type of effect requested - %x.\n",
effect->type);
return -EINVAL;
} }
/* If a packet was sent, forbid new updates until we are notified /* If a packet was sent, forbid new updates until we are notified
* that the packet was updated * that the packet was updated
...@@ -261,37 +260,36 @@ static int hid_pid_upload_effect(struct input_dev *dev, ...@@ -261,37 +260,36 @@ static int hid_pid_upload_effect(struct input_dev *dev,
int hid_pid_init(struct hid_device *hid) int hid_pid_init(struct hid_device *hid)
{ {
struct hid_ff_pid *private; struct hid_ff_pid *private;
struct hid_input *hidinput = list_entry(&hid->inputs, struct hid_input, list); struct hid_input *hidinput = list_entry(&hid->inputs, struct hid_input, list);
private = hid->ff_private = kmalloc(sizeof(struct hid_ff_pid), GFP_KERNEL); private = hid->ff_private = kcalloc(1, sizeof(struct hid_ff_pid), GFP_KERNEL);
if (!private) return -1; if (!private)
return -ENOMEM;
memset(private,0,sizeof(struct hid_ff_pid));
private->hid = hid;
hid->ff_private = private; /* 'cause memset can move the block away */
hid->ff_exit = hid_pid_exit;
private->hid = hid; hid->ff_event = hid_pid_event;
hid->ff_exit = hid_pid_exit; /* Open output URB */
hid->ff_event = hid_pid_event; if (!(private->urbffout = usb_alloc_urb(0, GFP_KERNEL))) {
kfree(private);
/* Open output URB */ return -1;
if (!(private->urbffout = usb_alloc_urb(0, GFP_KERNEL))) { }
kfree(private);
return -1; usb_fill_control_urb(private->urbffout, hid->dev, 0,
} (void *)&private->ffcr, private->ctrl_buffer, 8,
hid_pid_ctrl_out, hid);
usb_fill_control_urb(private->urbffout, hid->dev,0,(void *) &private->ffcr,private->ctrl_buffer,8,hid_pid_ctrl_out,hid); hidinput->input.upload_effect = hid_pid_upload_effect;
hidinput->input.upload_effect = hid_pid_upload_effect; hidinput->input.flush = hid_pid_flush;
hidinput->input.flush = hid_pid_flush; hidinput->input.ff_effects_max = 8; // A random default
hidinput->input.ff_effects_max = 8; // A random default set_bit(EV_FF, hidinput->input.evbit);
set_bit(EV_FF, hidinput->input.evbit); set_bit(EV_FF_STATUS, hidinput->input.evbit);
set_bit(EV_FF_STATUS, hidinput->input.evbit);
spin_lock_init(&private->lock);
spin_lock_init(&private->lock);
printk(KERN_INFO "Force feedback driver for PID devices by Rodrigo Damazio <rdamazio@lsi.usp.br>.\n");
printk(KERN_INFO "Force feedback driver for PID devices by Rodrigo Damazio <rdamazio@lsi.usp.br>.\n");
return 0;
return 0;
} }
...@@ -25,31 +25,31 @@ ...@@ -25,31 +25,31 @@
#define FF_EFFECTS_MAX 64 #define FF_EFFECTS_MAX 64
#define FF_PID_FLAGS_USED 1 /* If the effect exists */ #define FF_PID_FLAGS_USED 1 /* If the effect exists */
#define FF_PID_FLAGS_UPDATING 2 /* If the effect is being updated */ #define FF_PID_FLAGS_UPDATING 2 /* If the effect is being updated */
#define FF_PID_FLAGS_PLAYING 3 /* If the effect is currently being played */ #define FF_PID_FLAGS_PLAYING 3 /* If the effect is currently being played */
#define FF_PID_FALSE 0 #define FF_PID_FALSE 0
#define FF_PID_TRUE 1 #define FF_PID_TRUE 1
struct hid_pid_effect { struct hid_pid_effect {
unsigned long flags; unsigned long flags;
pid_t owner; pid_t owner;
unsigned int device_id; // The device-assigned ID unsigned int device_id; /* The device-assigned ID */
struct ff_effect effect; struct ff_effect effect;
}; };
struct hid_ff_pid { struct hid_ff_pid {
struct hid_device *hid; struct hid_device *hid;
unsigned long int gain; unsigned long gain;
struct urb *urbffout; struct urb *urbffout;
struct usb_ctrlrequest ffcr; struct usb_ctrlrequest ffcr;
spinlock_t lock; spinlock_t lock;
char ctrl_buffer[8]; unsigned char ctrl_buffer[8];
struct hid_pid_effect effects[FF_EFFECTS_MAX]; struct hid_pid_effect effects[FF_EFFECTS_MAX];
}; };
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment