]> rtime.felk.cvut.cz Git - shark/motorek-5200.git/commitdiff
Both directions work; added action attribute
authorMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 15 Jan 2009 12:51:22 +0000 (13:51 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Thu, 15 Jan 2009 12:51:22 +0000 (13:51 +0100)
motorek.c

index 83ee1d8cfbdaf7dcbc9a14aeb08e9b992199367a..86577b11371ff698f5bf0b770e090dd73230a051 100644 (file)
--- 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;