Revision: 82 http://acme-dev.svn.sourceforge.net/acme-dev/?rev=82&view=rev Author: claudyus Date: 2011-05-21 08:40:26 +0000 (Sat, 21 May 2011) Log Message: ----------- stepper-drv: Update to latest kernel api Modified Paths: -------------- kernel-stuff/stepper-driver/stepper-nopwm.c Modified: kernel-stuff/stepper-driver/stepper-nopwm.c =================================================================== --- kernel-stuff/stepper-driver/stepper-nopwm.c 2011-03-25 11:54:28 UTC (rev 81) +++ kernel-stuff/stepper-driver/stepper-nopwm.c 2011-05-21 08:40:26 UTC (rev 82) @@ -38,7 +38,7 @@ struct class *motor_class; static dev_t motor_devno = 0; -struct motor_device { +static struct motor_device { unsigned long steps_max; unsigned long steps; @@ -48,12 +48,12 @@ int g_lpwr; int polarity; - struct hrtimer t; + struct hrtimer *t; int status; ktime_t interval; - struct cdev *motor_cdev; -}; + struct cdev *mcdev; +} motor[MAX_MOT_NUM]; static unsigned int mot0[6] __initdata; static unsigned int mot1[6] __initdata; @@ -62,10 +62,8 @@ static unsigned int mot_nump[MAX_MOT_NUM] __initdata; -static struct motor_device motor[MAX_MOT_NUM]; - #define BUS_PARM_DESC \ - " config -> id,en,dir,step[,lowpwr,polarity]" + " config -> en,dir,step[,lowpwr,polarity]" module_param_array(mot0, uint, &mot_nump[0], 0); MODULE_PARM_DESC(mot0, "mot0" BUS_PARM_DESC); @@ -76,11 +74,11 @@ module_param_array(mot3, uint, &mot_nump[3], 0); MODULE_PARM_DESC(mot3, "mot3" BUS_PARM_DESC); -static int motor_pwm_set(unsigned long val, int id) { +static int motor_pwm_set(struct motor_device *motp, unsigned long val) { if (val == 0) val =1; - motor[id].interval = ktime_set(0, val * 1000000UL); + motp->interval = ktime_set(0, val * 1000000UL); return 0; } @@ -102,7 +100,7 @@ if (mot->steps >= mot->steps_max) { hrtimer_try_to_cancel(&(mot->t)); } else { - hrtimer_forward(&(mot->t), ktime_get(), mot->interval); + hrtimer_forward(mot->t, ktime_get(), mot->interval); return HRTIMER_RESTART; } @@ -110,15 +108,17 @@ } /* IOCTL interface */ -static int motor_ioctl (/* struct inode *inode, */ struct file *file, unsigned int cmd, unsigned long arg){ +static long motor_ioctl (struct file *file, unsigned int cmd, unsigned long arg){ - int retval = 0, id; + int retval = 0; unsigned long to_end; /* Ioctl was recently restructured http://lwn.net/Articles/119652/ */ - struct cdev *p = file->f_dentry->d_inode->i_cdev; - struct motor_device *mot = container_of(p, struct motor_device, motor_cdev); + struct cdev *cdevp = file->f_dentry->d_inode->i_cdev; + struct motor_device *mot = container_of(cdevp, struct motor_device, mcdev); + printk(KERN_INFO "stepper: ioctl if: command %d args %ld \n", cmd, arg); + switch (cmd) { case MOTOR_ENABLE: if ((int)arg) @@ -135,16 +135,16 @@ break; case MOTOR_PWM_ON: - hrtimer_start(&(mot->t), mot->interval, HRTIMER_MODE_REL); + hrtimer_start(mot->t, mot->interval, HRTIMER_MODE_REL); break; case MOTOR_PWM_OFF: - hrtimer_cancel(&(mot->t)); + hrtimer_cancel(mot->t); break; case MOTOR_PWM_SET: //set the pwm period in ms - motor_pwm_set (arg, id); + motor_pwm_set (mot, arg); break; case MOTOR_RESET: @@ -187,40 +187,34 @@ static int __init motor_add_one(unsigned int id, unsigned int *params) { int status; - struct cdev *motor_cdev; -// struct platform_device *pdev; - //struct gpio_pwm_platform_data pdata; - if ( mot_nump[id] < 4 ) { - printk(KERN_INFO "stepper: nothing to register for id: %d.\n", id); + if ( mot_nump[id] < 3 ) { + printk(KERN_INFO "stepper: nothing to register for motor %d, too few arguments: %d.\n", id, mot_nump[id]); return 0; } +// Supported args: motX=en,dir,step[,lowpwr,polarity] + motor[id].g_enable = params[0]; + motor[id].g_dir = params[1]; + motor[id].g_step = params[2]; + motor[id].g_lpwr = params[3]; + motor[id].polarity = params[4]; - motor[id].g_enable = params[1]; - motor[id].g_dir = params[2]; - motor[id].g_step = params[3]; - motor[id].g_lpwr = params[4]; - motor[id].polarity = params[5]; - /* sanity check */ if ( !( motor[id].g_enable && motor[id].g_dir && motor[id].g_step)) { printk(KERN_INFO "stepper: missing parameters, exit driver.\n"); goto err_para; } -// INIT_WORK(&work[id], gpio_hr_work); +// INIT_WORK(work[id], gpio_hr_work); if (gpio_request(motor[id].g_step, "motor-step")) return -EINVAL; - hrtimer_init(&(motor[id].t), CLOCK_MONOTONIC, HRTIMER_MODE_REL); + hrtimer_init(motor[id].t, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - motor[id].t.function = &gpio_timeout; -// mot_map_hrtimer[id] = &t[id]; + motor[id].t->function = &gpio_timeout; motor[id].interval = ktime_set(0, 10000000UL); - //motor_pwm_set(1, id); - if ( gpio_request(motor[id].g_enable, "motor-enable") < 0 ) { goto err_gpioenable; } @@ -242,26 +236,26 @@ /* set to home */ motor[id].steps = 0; - /* alloc a new device number (major: dynamic, minor: 0) */ - status = alloc_chrdev_region(&motor_devno, 0, 1, "motor"); + /* alloc a new device number (major: dynamic, minor: id) */ + status = alloc_chrdev_region(&motor_devno, id, 1, "motor"); /* create a new char device */ - motor[id].motor_cdev = cdev_alloc(); - if(motor[id].motor_cdev == NULL) { + motor[id].mcdev = cdev_alloc(); + if(motor[id].mcdev == NULL) { status=-ENOMEM; goto err_dev; } - motor[id].motor_cdev->owner = THIS_MODULE; - motor[id].motor_cdev->ops = &motor_fops; - status = cdev_add(motor[id].motor_cdev, motor_devno, 1); + motor[id].mcdev->owner = THIS_MODULE; + motor[id].mcdev->ops = &motor_fops; + status = cdev_add(motor[id].mcdev, motor_devno, 1); if(status){ goto err_dev; } - device_create(motor_class, NULL, motor_devno, NULL, "motor%d", params[0]); + device_create(motor_class, NULL, motor_devno, NULL, "motor%d", id); printk(KERN_INFO "stepper: motor%d registred on major: %u; minor: %u\n", \ - params[0], MAJOR(motor_devno), MINOR(motor_devno)); + id, MAJOR(motor_devno), MINOR(motor_devno)); return 0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.