1 Index: linux-2.6.32.26/drivers/vlynq/vlynq.c
2 ===================================================================
3 --- linux-2.6.32.26.orig/drivers/vlynq/vlynq.c 2010-11-24 13:01:20.459985351 -0800
4 +++ linux-2.6.32.26/drivers/vlynq/vlynq.c 2010-11-24 13:01:43.537494084 -0800
9 +u32 __vlynq_rev_reg(struct vlynq_regs *regs)
11 + return readl(®s->revision);
13 +EXPORT_SYMBOL(__vlynq_rev_reg);
15 /* Check the VLYNQ link status with a given device */
16 static int vlynq_linked(struct vlynq_device *dev)
22 +static volatile int vlynq_delay_value_new = 0;
24 +static void vlynq_delay_wait(u32 count)
26 + /* Code adopted from original vlynq driver */
28 + volatile int *ptr = &vlynq_delay_value_new;
31 + /* We are assuming that the each cycle takes about
32 + * 23 assembly instructions. */
33 + for(i = 0; i < (count + 23)/23; i++)
37 static void vlynq_reset(struct vlynq_device *dev)
39 + u32 rtm = readl(&dev->local->revision);
41 + if (rtm < 0x00010200)
44 + rtm = rtm < 0x00010205 || readl(&dev->local->status) & 0x800 == 0 ?
47 writel(readl(&dev->local->control) | VLYNQ_CTRL_RESET,
48 &dev->local->control);
50 /* Wait for the devices to finish resetting */
52 + vlynq_delay_wait(0xffffff);
54 /* Remove reset bit */
55 - writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET,
56 + writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET | rtm,
57 &dev->local->control);
59 /* Give some time for the devices to settle */
61 + vlynq_delay_wait(0xffffff);
64 static void vlynq_irq_unmask(unsigned int irq)
67 EXPORT_SYMBOL(vlynq_unregister_driver);
76 +static int __vlynq_set_clocks(struct vlynq_device *dev,
77 + enum vlynq_clk_src clk_dir,
78 + int lclk_div, int rclk_div)
82 + if (clk_dir == vlynq_clk_invalid) {
83 + printk(KERN_ERR "%s: attempt to set invalid clocking\n",
84 + dev_name(&dev->dev));
88 + printk(KERN_INFO "%s: local VLYNQ protocol rev. is 0x%08x\n",
89 + dev_name(&dev->dev), readl(&dev->local->revision));
91 + reg = readl(&dev->local->control);
92 + if (readl(&dev->local->revision) < 0x00010205) {
93 + if (clk_dir & vlynq_clk_local)
94 + reg |= VLYNQ_CTRL_CLOCK_INT;
96 + reg &= ~VLYNQ_CTRL_CLOCK_INT;
98 + reg &= ~VLYNQ_CTRL_CLOCK_MASK;
99 + reg |= VLYNQ_CTRL_CLOCK_DIV(lclk_div);
100 + writel(reg, &dev->local->control);
102 + if (!vlynq_linked(dev))
105 + printk(KERN_INFO "%s: remote VLYNQ protocol rev. is 0x%08x\n",
106 + dev_name(&dev->dev), readl(&dev->remote->revision));
108 + reg = readl(&dev->remote->control);
109 + if (readl(&dev->remote->revision) < 0x00010205) {
110 + if (clk_dir & vlynq_clk_remote)
111 + reg |= VLYNQ_CTRL_CLOCK_INT;
113 + reg &= ~VLYNQ_CTRL_CLOCK_INT;
115 + reg &= ~VLYNQ_CTRL_CLOCK_MASK;
116 + reg |= VLYNQ_CTRL_CLOCK_DIV(rclk_div);
117 + writel(reg, &dev->remote->control);
119 + if (!vlynq_linked(dev))
126 * A VLYNQ remote device can clock the VLYNQ bus master
127 * using a dedicated clock line. In that case, both the
128 @@ -392,29 +477,15 @@
132 - for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
133 - i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
134 - dev->dev_id ? i++ : i--) {
136 + for (i = 0; i <= 7; i++) {
137 if (!vlynq_linked(dev))
140 - writel((readl(&dev->remote->control) &
141 - ~VLYNQ_CTRL_CLOCK_MASK) |
142 - VLYNQ_CTRL_CLOCK_INT |
143 - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
144 - &dev->remote->control);
145 - writel((readl(&dev->local->control)
146 - & ~(VLYNQ_CTRL_CLOCK_INT |
147 - VLYNQ_CTRL_CLOCK_MASK)) |
148 - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
149 - &dev->local->control);
151 - if (vlynq_linked(dev)) {
152 + if (!__vlynq_set_clocks(dev, vlynq_clk_remote, i, i)) {
154 - "%s: using remote clock divisor %d\n",
155 - dev_name(&dev->dev), i - vlynq_rdiv1 + 1);
157 + "%s: using remote clock divisor %d\n",
158 + dev_name(&dev->dev), i + 1);
159 + dev->divisor = i + vlynq_rdiv1;
163 @@ -437,21 +508,12 @@
167 - for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
168 - i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
169 - dev->dev_id ? i++ : i--) {
171 - writel((readl(&dev->local->control) &
172 - ~VLYNQ_CTRL_CLOCK_MASK) |
173 - VLYNQ_CTRL_CLOCK_INT |
174 - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1),
175 - &dev->local->control);
177 - if (vlynq_linked(dev)) {
178 + for (i = 0; i <= 7; i++) {
179 + if (!__vlynq_set_clocks(dev, vlynq_clk_local, i, 0)) {
181 - "%s: using local clock divisor %d\n",
182 - dev_name(&dev->dev), i - vlynq_ldiv1 + 1);
184 + "%s: using local clock divisor %d\n",
185 + dev_name(&dev->dev), i + 1);
186 + dev->divisor = i + vlynq_ldiv1;
190 @@ -473,18 +535,10 @@
191 if (!vlynq_linked(dev))
194 - writel((readl(&dev->remote->control) &
195 - ~VLYNQ_CTRL_CLOCK_INT),
196 - &dev->remote->control);
198 - writel((readl(&dev->local->control) &
199 - ~VLYNQ_CTRL_CLOCK_INT),
200 - &dev->local->control);
202 - if (vlynq_linked(dev)) {
203 + if (!__vlynq_set_clocks(dev, vlynq_clk_external, 0, 0)) {
204 printk(KERN_DEBUG "%s: using external clock\n",
205 - dev_name(&dev->dev));
206 - dev->divisor = vlynq_div_external;
207 + dev_name(&dev->dev));
208 + dev->divisor = vlynq_div_external;
213 * generation negotiated by hardware.
214 * Check which device is generating clocks and perform setup
216 - if (vlynq_linked(dev) && readl(&dev->remote->control) &
217 - VLYNQ_CTRL_CLOCK_INT) {
218 - if (!__vlynq_try_remote(dev) ||
219 - !__vlynq_try_local(dev) ||
220 - !__vlynq_try_external(dev))
223 - if (!__vlynq_try_external(dev) ||
224 - !__vlynq_try_local(dev) ||
225 - !__vlynq_try_remote(dev))
228 + if (!__vlynq_try_remote(dev) || !__vlynq_try_local(dev) ||
229 + !__vlynq_try_external(dev))
234 @@ -528,15 +573,12 @@
238 - writel(VLYNQ_CTRL_CLOCK_INT |
239 - VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
240 - vlynq_ldiv1), &dev->local->control);
241 - writel(0, &dev->remote->control);
242 - if (vlynq_linked(dev)) {
243 + if (!__vlynq_set_clocks(dev, vlynq_clk_local, dev->divisor -
246 - "%s: using local clock divisor %d\n",
247 - dev_name(&dev->dev),
248 - dev->divisor - vlynq_ldiv1 + 1);
249 + "%s: using local clock divisor %d\n",
250 + dev_name(&dev->dev),
251 + dev->divisor - vlynq_ldiv1 + 1);
255 @@ -548,15 +590,12 @@
259 - writel(0, &dev->local->control);
260 - writel(VLYNQ_CTRL_CLOCK_INT |
261 - VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
262 - vlynq_rdiv1), &dev->remote->control);
263 - if (vlynq_linked(dev)) {
264 + if (!__vlynq_set_clocks(dev, vlynq_clk_remote, 0,
265 + dev->divisor - vlynq_rdiv1)) {
267 - "%s: using remote clock divisor %d\n",
268 - dev_name(&dev->dev),
269 - dev->divisor - vlynq_rdiv1 + 1);
270 + "%s: using remote clock divisor %d\n",
271 + dev_name(&dev->dev),
272 + dev->divisor - vlynq_rdiv1 + 1);
276 @@ -732,13 +771,13 @@
277 platform_set_drvdata(pdev, dev);
279 printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
280 - dev_name(&dev->dev), (void *)dev->regs_start, dev->irq,
281 - (void *)dev->mem_start);
282 + dev_name(&dev->dev), (void *)dev->regs_start,
283 + dev->irq, (void *)dev->mem_start);
286 dev->divisor = vlynq_div_auto;
287 - result = __vlynq_enable_device(dev);
289 + if (__vlynq_enable_device(dev))
292 dev->dev_id = readl(&dev->remote->chip);
293 ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
295 Index: linux-2.6.32.26/include/linux/vlynq.h
296 ===================================================================
297 --- linux-2.6.32.26.orig/include/linux/vlynq.h 2010-11-24 13:07:33.297487888 -0800
298 +++ linux-2.6.32.26/include/linux/vlynq.h 2010-11-24 13:08:44.107488596 -0800
301 extern struct bus_type vlynq_bus_type;
303 +extern u32 __vlynq_rev_reg(struct vlynq_regs *regs);
304 extern int __vlynq_register_driver(struct vlynq_driver *driver,
305 struct module *owner);