linux-omap 2.6.37: replace various patch with upstream versions and rediff
[openembedded.git] / recipes / linux / linux-2.6.18 / at32-dac-oss-driver-clk-fix.patch
blob927cdc5ecee14fd2eea41571c5e9ceb3d8742184
1 ---
2 sound/oss/at32dac.c | 72 +++++++++++++++++++++++++++++++---------------------
3 1 file changed, 43 insertions(+), 29 deletions(-)
5 Index: linux-2.6.18-avr32/sound/oss/at32dac.c
6 ===================================================================
7 --- linux-2.6.18-avr32.orig/sound/oss/at32dac.c 2006-11-01 14:30:47.000000000 +0100
8 +++ linux-2.6.18-avr32/sound/oss/at32dac.c 2006-11-01 14:32:05.000000000 +0100
9 @@ -71,6 +71,7 @@ struct at32_dac {
10 struct dma_request_cyclic req;
12 struct clk *mck;
13 + struct clk *sample_clk;
14 struct platform_device *pdev;
15 int busy;
16 int playing;
17 @@ -116,24 +117,6 @@ static void at32dac_update_dma_tail(stru
21 -static int at32dac_start_genclock(struct at32_dac *dac)
23 - unsigned int div;
25 - div = ((clk_get_rate(boot_cpu_data.clk) + 256 * dac->dsp_settings.sample_rate)
26 - / (512 * dac->dsp_settings.sample_rate) - 1);
27 - pr_debug("Real sample rate: %llu (div=%u)\n",
28 - boot_cpu_data.cpu_hz / (512 * (div + 1)), div);
29 - writel((div << 8) | 0x16, (void __iomem *)(0xfff00060 + 4 * 6));
31 - return 0;
34 -static void at32dac_stop_genclock(struct at32_dac *dac)
36 - writel(0, (void __iomem *)(0xfff00060 + 4 * 6));
39 static int at32dac_start(struct at32_dac *dac)
41 int ret;
42 @@ -143,13 +126,11 @@ static int at32dac_start(struct at32_dac
44 memset(dac->dma.buf, 0, DMA_BUFFER_SIZE);
46 - ret = at32dac_start_genclock(dac);
47 - if (ret)
48 - return ret;
49 + clk_enable(dac->sample_clk);
51 ret = dma_prepare_request_cyclic(dac->req.req.dmac, &dac->req);
52 if (ret)
53 - goto out_stop_genclock;
54 + goto out_stop_clock;
56 pr_debug("Starting DMA...\n");
57 ret = dma_start_request(dac->req.req.dmac, dac->req.req.channel);
58 @@ -164,8 +145,8 @@ static int at32dac_start(struct at32_dac
59 out_stop_request:
60 dma_stop_request(dac->req.req.dmac,
61 dac->req.req.channel);
62 -out_stop_genclock:
63 - at32dac_stop_genclock(dac);
64 +out_stop_clock:
65 + clk_disable(dac->sample_clk);
66 return ret;
69 @@ -176,7 +157,7 @@ static int at32dac_stop(struct at32_dac
70 dac_writel(dac, DATA, 0);
71 dac_writel(dac, CTRL, 0);
72 dac->playing = 0;
73 - at32dac_stop_genclock(dac);
74 + clk_disable(dac->sample_clk);
77 return 0;
78 @@ -360,6 +341,26 @@ static int at32dac_set_format(struct at3
79 return 0;
82 +static int at32dac_set_sample_rate(struct at32_dac *dac, unsigned long rate)
84 + unsigned long new_rate;
85 + int ret;
87 + ret = clk_set_rate(dac->sample_clk, 256 * rate);
88 + if (ret < 0)
89 + return ret;
91 + /* TODO: mplayer seems to have a problem with this */
92 +#if 0
93 + new_rate = clk_get_rate(dac->sample_clk);
94 + dac->dsp_settings.sample_rate = new_rate / 256;
95 +#else
96 + dac->dsp_settings.sample_rate = rate;
97 +#endif
99 + return 0;
102 static ssize_t at32dac_dsp_write(struct file *file,
103 const char __user *buffer,
104 size_t count, loff_t *ppos)
105 @@ -449,7 +450,9 @@ static int at32dac_dsp_ioctl(struct inod
106 return -EFAULT;
107 if (val >= 0) {
108 at32dac_stop(dac);
109 - dac->dsp_settings.sample_rate = val;
110 + ret = at32dac_set_sample_rate(dac, val);
111 + if (ret)
112 + return ret;
114 return put_user(dac->dsp_settings.sample_rate, up);
116 @@ -534,10 +537,11 @@ static int at32dac_dsp_open(struct inode
117 dac->dma.head = dac->dma.tail = 0;
119 /* FIXME: What are the correct defaults? */
120 - dac->dsp_settings.format = AFMT_S16_BE;
121 dac->dsp_settings.channels = 2;
122 - dac->dsp_settings.sample_rate = 8000;
123 - dac->dsp_settings.input_order = 2;
124 + at32dac_set_format(dac, AFMT_S16_BE);
125 + ret = at32dac_set_sample_rate(dac, 8000);
126 + if (ret)
127 + goto out;
129 file->private_data = dac;
130 dac->busy = 1;
131 @@ -578,6 +582,7 @@ static int __devinit at32dac_probe(struc
132 struct at32_dac *dac;
133 struct resource *regs;
134 struct clk *mck;
135 + struct clk *sample_clk;
136 int irq;
137 int ret;
139 @@ -594,6 +599,11 @@ static int __devinit at32dac_probe(struc
140 mck = clk_get(&pdev->dev, "mck");
141 if (IS_ERR(mck))
142 return PTR_ERR(mck);
143 + sample_clk = clk_get(&pdev->dev, "sample_clk");
144 + if (IS_ERR(sample_clk)) {
145 + ret = PTR_ERR(sample_clk);
146 + goto out_put_mck;
148 clk_enable(mck);
150 ret = -ENOMEM;
151 @@ -606,6 +616,7 @@ static int __devinit at32dac_probe(struc
152 init_waitqueue_head(&dac->write_wait);
153 dac->pdev = pdev;
154 dac->mck = mck;
155 + dac->sample_clk = sample_clk;
157 dac->regs = ioremap(regs->start, regs->end - regs->start + 1);
158 if (!dac->regs)
159 @@ -658,6 +669,8 @@ out_free_dac:
160 kfree(dac);
161 out_disable_clk:
162 clk_disable(mck);
163 + clk_put(sample_clk);
164 +out_put_mck:
165 clk_put(mck);
166 return ret;
168 @@ -673,6 +686,7 @@ static int __devexit at32dac_remove(stru
169 free_irq(platform_get_irq(pdev, 0), dac);
170 iounmap(dac->regs);
171 clk_disable(dac->mck);
172 + clk_put(dac->sample_clk);
173 clk_put(dac->mck);
174 kfree(dac);
175 platform_set_drvdata(pdev, NULL);