d43848556c850f96bb1e00356a01c1c4da142dd6
[kernel-power] / kernel-power-2.6.28 / debian / patches / radio-si4713.diff
1 --- kernel-power-2.6.28/drivers/media/radio/radio-si4713.c      2012-02-17 20:44:03.508286080 +0100
2 +++ kernel-power-2.6.28/drivers/media/radio/radio-si4713.c      2012-02-17 20:45:13.976284020 +0100
3 @@ -55,23 +55,10 @@
4  static int radio_nr = -1;      /* radio device minor (-1 ==> auto assign) */
5  
6  /* properties lock for write operations */
7 -static int config_locked;
8 +static int config_locked = 1;
9  
10 -/* saved power levels */
11 -static unsigned int max_pl;
12 -static unsigned int min_pl;
13 -
14 -/* structure for pid registration */
15 -struct pid_list {
16 -       pid_t pid;
17 -       struct list_head plist;
18 -};
19 -
20 -#define APP_MAX_NUM    2
21 -
22 -static int pid_count;
23 -static LIST_HEAD(pid_list_head);
24 -static struct si4713_device *si4713_dev;
25 +/* module param for initial power level */
26 +static int init_power_level = 120;
27  
28  /*
29   * Sysfs properties
30 @@ -193,17 +180,15 @@ static ssize_t si4713_lock_write(struct
31                                 const char *buf,
32                                 size_t count)
33  {
34         int l;
35  
36 -       if (config_locked)
37 -               return -EPERM;
38 -
39         sscanf(buf, "%d", &l);
40  
41 -       if (l != 0)
42 -               config_locked = 1;
43 +       if (l != 0 && l != 1)
44 +               return -EINVAL;
45  
46 +       config_locked = l;
47         return count;
48  }
49  
50  static ssize_t si4713_lock_read(struct device *dev,
51 @@ -219,7 +196,7 @@ static DEVICE_ATTR(lock, S_IRUGO | S_IWU
52  /*
53   * Power level property
54   */
55 -/* power_level (rw) 88 - 115 or 0 */
56 +/* power_level (rw) 88 - 120 or 0 */
57  static ssize_t si4713_power_level_write(struct device *dev,
58                                         struct device_attribute *attr,
59                                         const char *buf,
60 @@ -230,7 +207,7 @@ static ssize_t si4713_power_level_write(
61         int rval, pl;
62  
63         if (config_locked)
64 -               return -EPERM;
65 +               return count;
66  
67         if (!sdev) {
68                 rval = -ENODEV;
69 @@ -420,109 +397,13 @@ static irqreturn_t si4713_handler(int ir
70         return IRQ_HANDLED;
71  }
72  
73 -static int register_pid(pid_t pid)
74 -{
75 -       struct pid_list *pitem;
76 -
77 -       list_for_each_entry(pitem, &pid_list_head, plist) {
78 -               if (pitem->pid == pid)
79 -                       return -EINVAL;
80 -       }
81 -
82 -       pitem = kmalloc(sizeof(struct pid_list), GFP_KERNEL);
83 -
84 -       if (!pitem)
85 -               return -ENOMEM;
86 -
87 -       pitem->pid = pid;
88 -
89 -       list_add(&(pitem->plist), &pid_list_head);
90 -       pid_count++;
91 -
92 -       return 0;
93 -}
94 -
95 -static int unregister_pid(pid_t pid)
96 -{
97 -       struct pid_list *pitem, *n;
98 -
99 -       list_for_each_entry_safe(pitem, n, &pid_list_head, plist) {
100 -               if (pitem->pid == pid) {
101 -                       list_del(&(pitem->plist));
102 -                       pid_count--;
103 -
104 -                       kfree(pitem);
105 -
106 -                       return 0;
107 -               }
108 -       }
109 -       return -EINVAL;
110 -}
111 -
112  static int si4713_priv_ioctl(struct inode *inode, struct file *file,
113                 unsigned int cmd, unsigned long arg)
114  {
115 -       unsigned int pow;
116 -       int pl, rval;
117 -
118         if (cmd != LOCK_LOW_POWER && cmd != RELEASE_LOW_POWER)
119                 return video_ioctl2(inode, file, cmd, arg);
120 -
121 -       pl = si4713_get_power_level(si4713_dev);
122 -
123 -       if (pl < 0) {
124 -               rval = pl;
125 -               goto exit;
126 -       }
127 -
128 -       if (copy_from_user(&pow, (void __user *)arg, sizeof(pow))) {
129 -               rval = -EFAULT;
130 -               goto exit;
131 -       }
132 -
133 -       if (cmd == LOCK_LOW_POWER) {
134 -
135 -               if (pid_count == APP_MAX_NUM) {
136 -                       rval = -EPERM;
137 -                       goto exit;
138 -               }
139 -
140 -               if (pid_count == 0) {
141 -                       if (pow > pl) {
142 -                               rval = -EINVAL;
143 -                               goto exit;
144 -                       } else {
145 -                               /* Set max possible power level */
146 -                               max_pl = pl;
147 -                               min_pl = pow;
148 -                       }
149 -               }
150 -
151 -               rval = register_pid(current->pid);
152 -
153 -               if (rval)
154 -                       goto exit;
155 -
156 -               /* Lower min power level if asked */
157 -               if (pow < min_pl)
158 -                       min_pl = pow;
159 -               else
160 -                       pow = min_pl;
161 -
162 -       } else { /* RELEASE_LOW_POWER */
163 -               rval = unregister_pid(current->pid);
164 -
165 -               if (rval)
166 -                       goto exit;
167 -
168 -               if (pid_count == 0) {
169 -                       if (pow > max_pl)
170 -                               pow = max_pl;
171 -               }
172 -       }
173 -       rval = si4713_set_power_level(si4713_dev, pow);
174 -exit:
175 -       return rval;
176 +       else
177 +               return 0;
178  }
179  
180  /*
181 @@ -906,8 +787,11 @@ static int si4713_i2c_driver_probe(struc
182                 goto free_sysfs;
183         }
184  
185 -       /* save to global pointer for it to be accesible from ioctl() call */
186 -       si4713_dev = sdev;
187 +       rval = si4713_set_power_level(sdev, init_power_level);
188 +       if (rval < 0) {
189 +               dev_dbg(&client->dev, "Failed to set initial power level.\n");
190 +               goto free_sysfs;
191 +       }
192  
193         return 0;
194  
195 @@ -1013,6 +897,12 @@ module_param(radio_nr, int, 0);
196  MODULE_PARM_DESC(radio_nr,
197                  "Minor number for radio device (-1 ==> auto assign)");
198  
199 +module_param(init_power_level, int, 120);
200 +MODULE_PARM_DESC(init_power_level, "Initial value of power level (default 120)");
201 +
202 +module_param(config_locked, int, 1);
203 +MODULE_PARM_DESC(config_locked, "Lock power level configuration on init (default 1 - locked)");
204 +
205  MODULE_LICENSE("GPL");
206  MODULE_AUTHOR(DRIVER_AUTHOR);
207  MODULE_DESCRIPTION(DRIVER_DESC);