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-22 10:48:20.000000000 -0800
4 +++ linux-2.6.32.26/drivers/vlynq/vlynq.c 2010-11-28 02:56:51.972405343 -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 + rtm = rtm < 0x00010205 || readl(&dev->local->status) & 0x800 == 0 ?
44 writel(readl(&dev->local->control) | VLYNQ_CTRL_RESET,
45 &dev->local->control);
47 /* Wait for the devices to finish resetting */
49 + vlynq_delay_wait(0xffffff);
51 /* Remove reset bit */
52 - writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET,
53 + writel(readl(&dev->local->control) & ~VLYNQ_CTRL_RESET | rtm,
54 &dev->local->control);
56 /* Give some time for the devices to settle */
58 + vlynq_delay_wait(0xffffff);
61 static void vlynq_irq_unmask(unsigned int irq)
64 EXPORT_SYMBOL(vlynq_unregister_driver);
73 +static int __vlynq_set_clocks(struct vlynq_device *dev,
74 + enum vlynq_clk_src clk_dir,
75 + int lclk_div, int rclk_div)
79 + if (clk_dir == vlynq_clk_invalid) {
80 + printk(KERN_ERR "%s: attempt to set invalid clocking\n",
81 + dev_name(&dev->dev));
85 + reg = readl(&dev->local->control);
86 + if (readl(&dev->local->revision) < 0x00010205) {
87 + if (clk_dir & vlynq_clk_local)
88 + reg |= VLYNQ_CTRL_CLOCK_INT;
90 + reg &= ~VLYNQ_CTRL_CLOCK_INT;
92 + reg &= ~VLYNQ_CTRL_CLOCK_MASK;
93 + reg |= VLYNQ_CTRL_CLOCK_DIV(lclk_div);
94 + writel(reg, &dev->local->control);
96 + if (!vlynq_linked(dev))
99 + printk(KERN_INFO "%s: local VLYNQ protocol rev. is 0x%08x\n",
100 + dev_name(&dev->dev), readl(&dev->local->revision));
101 + printk(KERN_INFO "%s: remote VLYNQ protocol rev. is 0x%08x\n",
102 + dev_name(&dev->dev), readl(&dev->remote->revision));
104 + reg = readl(&dev->remote->control);
105 + if (readl(&dev->remote->revision) < 0x00010205) {
106 + if (clk_dir & vlynq_clk_remote)
107 + reg |= VLYNQ_CTRL_CLOCK_INT;
109 + reg &= ~VLYNQ_CTRL_CLOCK_INT;
111 + reg &= ~VLYNQ_CTRL_CLOCK_MASK;
112 + reg |= VLYNQ_CTRL_CLOCK_DIV(rclk_div);
113 + writel(reg, &dev->remote->control);
115 + if (!vlynq_linked(dev))
122 * A VLYNQ remote device can clock the VLYNQ bus master
123 * using a dedicated clock line. In that case, both the
124 @@ -392,29 +473,17 @@
128 - for (i = dev->dev_id ? vlynq_rdiv2 : vlynq_rdiv8; dev->dev_id ?
129 - i <= vlynq_rdiv8 : i >= vlynq_rdiv2;
130 - dev->dev_id ? i++ : i--) {
131 + for (i = dev->dev_id ? 0 : 7; dev->dev_id ? i <= 7 : i >= 0;
132 + dev->dev_id ? i++ : i--) {
134 if (!vlynq_linked(dev))
137 - writel((readl(&dev->remote->control) &
138 - ~VLYNQ_CTRL_CLOCK_MASK) |
139 - VLYNQ_CTRL_CLOCK_INT |
140 - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
141 - &dev->remote->control);
142 - writel((readl(&dev->local->control)
143 - & ~(VLYNQ_CTRL_CLOCK_INT |
144 - VLYNQ_CTRL_CLOCK_MASK)) |
145 - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_rdiv1),
146 - &dev->local->control);
148 - if (vlynq_linked(dev)) {
150 - "%s: using remote clock divisor %d\n",
151 - dev_name(&dev->dev), i - vlynq_rdiv1 + 1);
153 + if (!__vlynq_set_clocks(dev, vlynq_clk_remote, i, i)) {
155 + "%s: using remote clock divisor %d\n",
156 + dev_name(&dev->dev), i + 1);
157 + dev->divisor = i + vlynq_rdiv1;
161 @@ -437,21 +506,14 @@
165 - for (i = dev->dev_id ? vlynq_ldiv2 : vlynq_ldiv8; dev->dev_id ?
166 - i <= vlynq_ldiv8 : i >= vlynq_ldiv2;
167 - dev->dev_id ? i++ : i--) {
169 - writel((readl(&dev->local->control) &
170 - ~VLYNQ_CTRL_CLOCK_MASK) |
171 - VLYNQ_CTRL_CLOCK_INT |
172 - VLYNQ_CTRL_CLOCK_DIV(i - vlynq_ldiv1),
173 - &dev->local->control);
175 - if (vlynq_linked(dev)) {
177 - "%s: using local clock divisor %d\n",
178 - dev_name(&dev->dev), i - vlynq_ldiv1 + 1);
180 + for (i = dev->dev_id ? 0 : 7; dev->dev_id ? i <= 7 : i >= 0;
181 + dev->dev_id ? i++ : i--) {
183 + if (!__vlynq_set_clocks(dev, vlynq_clk_local, i, 0)) {
185 + "%s: using local clock divisor %d\n",
186 + dev_name(&dev->dev), i + 1);
187 + dev->divisor = i + vlynq_ldiv1;
191 @@ -473,18 +535,10 @@
192 if (!vlynq_linked(dev))
195 - writel((readl(&dev->remote->control) &
196 - ~VLYNQ_CTRL_CLOCK_INT),
197 - &dev->remote->control);
199 - writel((readl(&dev->local->control) &
200 - ~VLYNQ_CTRL_CLOCK_INT),
201 - &dev->local->control);
203 - if (vlynq_linked(dev)) {
204 - printk(KERN_DEBUG "%s: using external clock\n",
205 - dev_name(&dev->dev));
206 - dev->divisor = vlynq_div_external;
207 + if (!__vlynq_set_clocks(dev, vlynq_clk_external, 0, 0)) {
208 + printk(KERN_INFO "%s: using external clock\n",
209 + dev_name(&dev->dev));
210 + dev->divisor = vlynq_div_external;
215 * generation negotiated by hardware.
216 * Check which device is generating clocks and perform setup
218 - if (vlynq_linked(dev) && readl(&dev->remote->control) &
219 - VLYNQ_CTRL_CLOCK_INT) {
220 - if (!__vlynq_try_remote(dev) ||
221 - !__vlynq_try_local(dev) ||
222 - !__vlynq_try_external(dev))
225 - if (!__vlynq_try_external(dev) ||
226 - !__vlynq_try_local(dev) ||
227 - !__vlynq_try_remote(dev))
230 + if (!__vlynq_try_remote(dev) || !__vlynq_try_local(dev) ||
231 + !__vlynq_try_external(dev))
236 @@ -528,15 +573,12 @@
240 - writel(VLYNQ_CTRL_CLOCK_INT |
241 - VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
242 - vlynq_ldiv1), &dev->local->control);
243 - writel(0, &dev->remote->control);
244 - if (vlynq_linked(dev)) {
246 - "%s: using local clock divisor %d\n",
247 - dev_name(&dev->dev),
248 - dev->divisor - vlynq_ldiv1 + 1);
249 + if (!__vlynq_set_clocks(dev, vlynq_clk_local, dev->divisor -
252 + "%s: using local clock divisor %d\n",
253 + dev_name(&dev->dev),
254 + dev->divisor - vlynq_ldiv1 + 1);
258 @@ -548,15 +590,12 @@
262 - writel(0, &dev->local->control);
263 - writel(VLYNQ_CTRL_CLOCK_INT |
264 - VLYNQ_CTRL_CLOCK_DIV(dev->divisor -
265 - vlynq_rdiv1), &dev->remote->control);
266 - if (vlynq_linked(dev)) {
268 - "%s: using remote clock divisor %d\n",
269 - dev_name(&dev->dev),
270 - dev->divisor - vlynq_rdiv1 + 1);
271 + if (!__vlynq_set_clocks(dev, vlynq_clk_remote, 0,
272 + dev->divisor - vlynq_rdiv1)) {
274 + "%s: using remote clock divisor %d\n",
275 + dev_name(&dev->dev),
276 + dev->divisor - vlynq_rdiv1 + 1);
280 @@ -732,13 +771,12 @@
281 platform_set_drvdata(pdev, dev);
283 printk(KERN_INFO "%s: regs 0x%p, irq %d, mem 0x%p\n",
284 - dev_name(&dev->dev), (void *)dev->regs_start, dev->irq,
285 - (void *)dev->mem_start);
286 + dev_name(&dev->dev), (void *)dev->regs_start,
287 + dev->irq, (void *)dev->mem_start);
290 dev->divisor = vlynq_div_auto;
291 - result = __vlynq_enable_device(dev);
293 + if (!__vlynq_enable_device(dev)) {
294 dev->dev_id = readl(&dev->remote->chip);
295 ((struct plat_vlynq_ops *)(dev->dev.platform_data))->off(dev);
297 Index: linux-2.6.32.26/include/linux/vlynq.h
298 ===================================================================
299 --- linux-2.6.32.26.orig/include/linux/vlynq.h 2010-11-22 10:48:20.000000000 -0800
300 +++ linux-2.6.32.26/include/linux/vlynq.h 2010-11-27 12:08:39.312438011 -0800
303 extern struct bus_type vlynq_bus_type;
305 +extern u32 __vlynq_rev_reg(struct vlynq_regs *regs);
306 extern int __vlynq_register_driver(struct vlynq_driver *driver,
307 struct module *owner);