From a3b9c1e221a5021226ff415256ac4d148807553d Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Thu, 15 Jan 2009 13:51:22 +0100 Subject: [PATCH] Both directions work; added action attribute --- motorek.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/motorek.c b/motorek.c index 83ee1d8..86577b1 100644 --- a/motorek.c +++ b/motorek.c @@ -9,6 +9,7 @@ struct motorek { struct mpc52xx_gpt *pwmf, *pwmb; atomic_t pos; int irq; + int action; }; static ssize_t show_position(struct device *dev, @@ -21,7 +22,31 @@ static ssize_t show_position(struct device *dev, return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; } +static ssize_t show_action(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct platform_device *pdev = to_platform_device(dev); + struct motorek *m = platform_get_drvdata(pdev); + + int len = snprintf(buf, PAGE_SIZE, "%d\n", m->action); + return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; +} + +static void motorek_action(struct motorek *m, int action_permile); +static ssize_t store_action(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct platform_device *pdev = to_platform_device(dev); + struct motorek *m = platform_get_drvdata(pdev); + + int a; + sscanf(buf, "%d", &a); + motorek_action(m, a); + return strnlen(buf, PAGE_SIZE); +} + DEVICE_ATTR(position,0444,show_position,NULL); +DEVICE_ATTR(action,0644,show_action,store_action); #define MPC52xx_GPT_MODE_DISABLED 0 #define MPC52xx_GPT_MODE_INCAPT 1 @@ -57,6 +82,7 @@ static void pwm_done(struct mpc52xx_gpt *gpt) static void motorek_action(struct motorek *m, int action_permile) { + m->action = action_permile; if (action_permile >= 0) { pwm_width(m->pwmb, 0); pwm_width(m->pwmf, +action_permile*PWM_PERIOD/1000); @@ -70,9 +96,7 @@ static int __devinit motorek_init(struct motorek *m) { pwm_init(m->pwmf); pwm_init(m->pwmb); -/* motorek_action(m, +45); */ - pwm_width(m->pwmb, 500); - pwm_width(m->pwmf, 500); + //motorek_action(m, +0); return 0; } @@ -115,10 +139,10 @@ static int __devinit motorek_probe(struct platform_device *dev) if (prop) { i = *(u32 *)prop; switch (i) { - case 1: + case 2: m->pwmf = of_iomap(np, 0); break; - case 2: + case 3: m->pwmb = of_iomap(np, 0); break; } @@ -141,6 +165,9 @@ static int __devinit motorek_probe(struct platform_device *dev) platform_set_drvdata(dev, m); err = device_create_file(&dev->dev,&dev_attr_position); + if (err) + return err; + err = device_create_file(&dev->dev,&dev_attr_action); if (err) return err; -- 2.39.2