Blame view

arch/arm/mach-integrator/impd1.c 10.3 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /*
   *  linux/arch/arm/mach-integrator/impd1.c
   *
   *  Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
   *
   *  This file provides the core support for the IM-PD1 module.
   *
   * Module / boot parameters.
   *   lmid=n   impd1.lmid=n - set the logic module position in stack to 'n'
   */
  #include <linux/module.h>
  #include <linux/moduleparam.h>
  #include <linux/init.h>
  #include <linux/device.h>
  #include <linux/errno.h>
  #include <linux/mm.h>
a62c80e55   Russell King   [ARM] Move AMBA i...
21
22
  #include <linux/amba/bus.h>
  #include <linux/amba/clcd.h>
fced80c73   Russell King   [ARM] Convert asm...
23
  #include <linux/io.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
24
  #include <linux/slab.h>
6d803ba73   Jean-Christop PLAGNIOL-VILLARD   ARM: 6483/1: arm ...
25
  #include <linux/clkdev.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26

c5a0adb51   Russell King   ARM: ICST: kill d...
27
  #include <asm/hardware/icst.h>
a09e64fbc   Russell King   [ARM] Move includ...
28
29
  #include <mach/lm.h>
  #include <mach/impd1.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  #include <asm/sizes.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
36
37
38
  static int module_id;
  
  module_param_named(lmid, module_id, int, 0444);
  MODULE_PARM_DESC(lmid, "logic module stack position");
  
  struct impd1_module {
  	void __iomem	*base;
  	struct clk	vcos[2];
d72fbdf01   Russell King   [ARM] integrator:...
39
  	struct clk_lookup *clks[3];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
  };
39c0cb02d   Russell King   ARM: ICST: merge ...
41
  static const struct icst_params impd1_vco_params = {
64fceb1dc   Russell King   ARM: ICST: use Hz...
42
  	.ref		= 24000000,	/* 24 MHz */
4de2edbd1   Russell King   ARM: ICST: provid...
43
  	.vco_max	= ICST525_VCO_MAX_3V,
e73a46a3d   Russell King   ARM: ICST: move m...
44
  	.vco_min	= ICST525_VCO_MIN,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
47
48
  	.vd_min		= 12,
  	.vd_max		= 519,
  	.rd_min		= 3,
  	.rd_max		= 120,
232eaf7f2   Russell King   ARM: ICST: indire...
49
50
  	.s2div		= icst525_s2div,
  	.idx2s		= icst525_idx2s,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
  };
39c0cb02d   Russell King   ARM: ICST: merge ...
52
  static void impd1_setvco(struct clk *clk, struct icst_vco vco)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
  {
  	struct impd1_module *impd1 = clk->data;
d1914c7e7   Russell King   ARM: Make Integra...
55
  	u32 val = vco.v | (vco.r << 9) | (vco.s << 16);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
57
  
  	writel(0xa05f, impd1->base + IMPD1_LOCK);
d1914c7e7   Russell King   ARM: Make Integra...
58
  	writel(val, clk->vcoreg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  	writel(0, impd1->base + IMPD1_LOCK);
d18566376   Russell King   [ARM] Fix Integra...
60
  #ifdef DEBUG
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
63
  	vco.v = val & 0x1ff;
  	vco.r = (val >> 9) & 0x7f;
  	vco.s = (val >> 16) & 7;
64fceb1dc   Russell King   ARM: ICST: use Hz...
64
65
66
  	pr_debug("IM-PD1: VCO%d clock is %ld Hz
  ",
  		 vconr, icst525_hz(&impd1_vco_params, vco));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
67
68
  #endif
  }
9bf5b2ef6   Russell King   ARM: Indirect rou...
69
70
71
72
73
  static const struct clk_ops impd1_clk_ops = {
  	.round	= icst_clk_round,
  	.set	= icst_clk_set,
  	.setvco	= impd1_setvco,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
  {
  	struct impd1_module *impd1 = dev_get_drvdata(dev);
  	u32 cur;
  
  	val &= mask;
  	cur = readl(impd1->base + IMPD1_CTRL) & ~mask;
  	writel(cur | val, impd1->base + IMPD1_CTRL);
  }
  
  EXPORT_SYMBOL(impd1_tweak_control);
  
  /*
   * CLCD support
   */
  #define PANEL		PROSPECTOR
  
  #define LTM10C209		1
  #define PROSPECTOR		2
  #define SVGA			3
  #define VGA			4
  
  #if PANEL == VGA
  #define PANELTYPE	vga
  static struct clcd_panel vga = {
  	.mode		= {
  		.name		= "VGA",
  		.refresh	= 60,
  		.xres		= 640,
  		.yres		= 480,
  		.pixclock	= 39721,
  		.left_margin	= 40,
  		.right_margin	= 24,
  		.upper_margin	= 32,
  		.lower_margin	= 11,
  		.hsync_len	= 96,
  		.vsync_len	= 2,
  		.sync		= 0,
  		.vmode		= FB_VMODE_NONINTERLACED,
  	},
  	.width		= -1,
  	.height		= -1,
  	.tim2		= TIM2_BCD | TIM2_IPC,
  	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
9dfec4fe6   Russell King   ARM: integrator: ...
118
  	.caps		= CLCD_CAP_5551,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  	.connector	= IMPD1_CTRL_DISP_VGA,
  	.bpp		= 16,
  	.grayscale	= 0,
  };
  
  #elif PANEL == SVGA
  #define PANELTYPE	svga
  static struct clcd_panel svga = {
  	.mode		= {
  		.name		= "SVGA",
  		.refresh	= 0,
  		.xres		= 800,
  		.yres		= 600,
  		.pixclock	= 27778,
  		.left_margin	= 20,
  		.right_margin	= 20,
  		.upper_margin	= 5,
  		.lower_margin	= 5,
  		.hsync_len	= 164,
  		.vsync_len	= 62,
  		.sync		= 0,
  		.vmode		= FB_VMODE_NONINTERLACED,
  	},
  	.width		= -1,
  	.height		= -1,
  	.tim2		= TIM2_BCD,
  	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
  	.connector	= IMPD1_CTRL_DISP_VGA,
9dfec4fe6   Russell King   ARM: integrator: ...
147
  	.caps		= CLCD_CAP_5551,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  	.bpp		= 16,
  	.grayscale	= 0,
  };
  
  #elif PANEL == PROSPECTOR
  #define PANELTYPE	prospector
  static struct clcd_panel prospector = {
  	.mode		= {
  		.name		= "PROSPECTOR",
  		.refresh	= 0,
  		.xres		= 640,
  		.yres		= 480,
  		.pixclock	= 40000,
  		.left_margin	= 33,
  		.right_margin	= 64,
  		.upper_margin	= 36,
  		.lower_margin	= 7,
  		.hsync_len	= 64,
  		.vsync_len	= 25,
  		.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  		.vmode		= FB_VMODE_NONINTERLACED,
  	},
  	.width		= -1,
  	.height		= -1,
  	.tim2		= TIM2_BCD,
  	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
9dfec4fe6   Russell King   ARM: integrator: ...
174
  	.caps		= CLCD_CAP_5551,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  	.fixedtimings	= 1,
  	.connector	= IMPD1_CTRL_DISP_LCD,
  	.bpp		= 16,
  	.grayscale	= 0,
  };
  
  #elif PANEL == LTM10C209
  #define PANELTYPE	ltm10c209
  /*
   * Untested.
   */
  static struct clcd_panel ltm10c209 = {
  	.mode		= {
  		.name		= "LTM10C209",
  		.refresh	= 0,
  		.xres		= 640,
  		.yres		= 480,
  		.pixclock	= 40000,
  		.left_margin	= 20,
  		.right_margin	= 20,
  		.upper_margin	= 19,
  		.lower_margin	= 19,
  		.hsync_len	= 20,
  		.vsync_len	= 10,
  		.sync		= FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  		.vmode		= FB_VMODE_NONINTERLACED,
  	},
  	.width		= -1,
  	.height		= -1,
  	.tim2		= TIM2_BCD,
  	.cntl		= CNTL_LCDTFT | CNTL_LCDVCOMP(1),
9dfec4fe6   Russell King   ARM: integrator: ...
206
  	.caps		= CLCD_CAP_5551,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
  	.fixedtimings	= 1,
  	.connector	= IMPD1_CTRL_DISP_LCD,
  	.bpp		= 16,
  	.grayscale	= 0,
  };
  #endif
  
  /*
   * Disable all display connectors on the interface module.
   */
  static void impd1fb_clcd_disable(struct clcd_fb *fb)
  {
  	impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK, 0);
  }
  
  /*
   * Enable the relevant connector on the interface module.
   */
  static void impd1fb_clcd_enable(struct clcd_fb *fb)
  {
  	impd1_tweak_control(fb->dev->dev.parent, IMPD1_CTRL_DISP_MASK,
  			fb->panel->connector | IMPD1_CTRL_DISP_ENABLE);
  }
  
  static int impd1fb_clcd_setup(struct clcd_fb *fb)
  {
  	unsigned long framebase = fb->dev->res.start + 0x01000000;
  	unsigned long framesize = SZ_1M;
  	int ret = 0;
  
  	fb->panel = &PANELTYPE;
  
  	if (!request_mem_region(framebase, framesize, "clcd framebuffer")) {
  		printk(KERN_ERR "IM-PD1: unable to reserve framebuffer
  ");
  		return -EBUSY;
  	}
  
  	fb->fb.screen_base = ioremap(framebase, framesize);
  	if (!fb->fb.screen_base) {
  		printk(KERN_ERR "IM-PD1: unable to map framebuffer
  ");
  		ret = -ENOMEM;
  		goto free_buffer;
  	}
  
  	fb->fb.fix.smem_start	= framebase;
  	fb->fb.fix.smem_len	= framesize;
  
  	return 0;
  
   free_buffer:
  	release_mem_region(framebase, framesize);
  	return ret;
  }
  
  static int impd1fb_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
  {
  	unsigned long start, size;
  
  	start = vma->vm_pgoff + (fb->fb.fix.smem_start >> PAGE_SHIFT);
  	size = vma->vm_end - vma->vm_start;
  
  	return remap_pfn_range(vma, vma->vm_start, start, size,
  			       vma->vm_page_prot);
  }
  
  static void impd1fb_clcd_remove(struct clcd_fb *fb)
  {
  	iounmap(fb->fb.screen_base);
  	release_mem_region(fb->fb.fix.smem_start, fb->fb.fix.smem_len);
  }
  
  static struct clcd_board impd1_clcd_data = {
  	.name		= "IM-PD/1",
9dfec4fe6   Russell King   ARM: integrator: ...
282
  	.caps		= CLCD_CAP_5551 | CLCD_CAP_888,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
  	.check		= clcdfb_check,
  	.decode		= clcdfb_decode,
  	.disable	= impd1fb_clcd_disable,
  	.enable		= impd1fb_clcd_enable,
  	.setup		= impd1fb_clcd_setup,
  	.mmap		= impd1fb_clcd_mmap,
  	.remove		= impd1fb_clcd_remove,
  };
  
  struct impd1_device {
  	unsigned long	offset;
  	unsigned int	irq[2];
  	unsigned int	id;
  	void		*platform_data;
  };
  
  static struct impd1_device impd1_devs[] = {
  	{
  		.offset	= 0x03000000,
  		.id	= 0x00041190,
  	}, {
  		.offset	= 0x00100000,
  		.irq	= { 1 },
  		.id	= 0x00141011,
  	}, {
  		.offset	= 0x00200000,
  		.irq	= { 2 },
  		.id	= 0x00141011,
  	}, {
  		.offset	= 0x00300000,
  		.irq	= { 3 },
  		.id	= 0x00041022,
  	}, {
  		.offset	= 0x00400000,
  		.irq	= { 4 },
  		.id	= 0x00041061,
  	}, {
  		.offset	= 0x00500000,
  		.irq	= { 5 },
  		.id	= 0x00041061,
  	}, {
  		.offset	= 0x00600000,
  		.irq	= { 6 },
  		.id	= 0x00041130,
  	}, {
  		.offset	= 0x00700000,
  		.irq	= { 7, 8 },
  		.id	= 0x00041181,
  	}, {
  		.offset	= 0x00800000,
  		.irq	= { 9 },
  		.id	= 0x00041041,
  	}, {
  		.offset	= 0x01000000,
  		.irq	= { 11 },
  		.id	= 0x00041110,
  		.platform_data = &impd1_clcd_data,
  	}
  };
d72fbdf01   Russell King   [ARM] integrator:...
342
343
  static struct clk fixed_14745600 = {
  	.rate = 14745600,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
344
345
346
347
348
349
350
351
352
353
354
355
  };
  
  static int impd1_probe(struct lm_device *dev)
  {
  	struct impd1_module *impd1;
  	int i, ret;
  
  	if (dev->id != module_id)
  		return -EINVAL;
  
  	if (!request_mem_region(dev->resource.start, SZ_4K, "LM registers"))
  		return -EBUSY;
d2a02b93c   Russell King   [ARM] Convert kma...
356
  	impd1 = kzalloc(sizeof(struct impd1_module), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
357
358
359
360
  	if (!impd1) {
  		ret = -ENOMEM;
  		goto release_lm;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
361
362
363
364
365
366
367
368
  
  	impd1->base = ioremap(dev->resource.start, SZ_4K);
  	if (!impd1->base) {
  		ret = -ENOMEM;
  		goto free_impd1;
  	}
  
  	lm_set_drvdata(dev, impd1);
7c28472a5   Russell King   [ARM] integrator:...
369
370
371
  	printk("IM-PD1 found at 0x%08lx
  ",
  		(unsigned long)dev->resource.start);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
373
  
  	for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
9bf5b2ef6   Russell King   ARM: Indirect rou...
374
  		impd1->vcos[i].ops = &impd1_clk_ops,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
375
  		impd1->vcos[i].owner = THIS_MODULE,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
376
  		impd1->vcos[i].params = &impd1_vco_params,
9bf5b2ef6   Russell King   ARM: Indirect rou...
377
  		impd1->vcos[i].data = impd1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
378
  	}
d1914c7e7   Russell King   ARM: Make Integra...
379
380
  	impd1->vcos[0].vcoreg = impd1->base + IMPD1_OSC1;
  	impd1->vcos[1].vcoreg = impd1->base + IMPD1_OSC2;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381

d72fbdf01   Russell King   [ARM] integrator:...
382
383
384
385
386
387
388
389
  	impd1->clks[0] = clkdev_alloc(&impd1->vcos[0], NULL, "lm%x:01000",
  					dev->id);
  	impd1->clks[1] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00100",
  					dev->id);
  	impd1->clks[2] = clkdev_alloc(&fixed_14745600, NULL, "lm%x:00200",
  					dev->id);
  	for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
  		clkdev_add(impd1->clks[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
391
392
393
394
395
  	for (i = 0; i < ARRAY_SIZE(impd1_devs); i++) {
  		struct impd1_device *idev = impd1_devs + i;
  		struct amba_device *d;
  		unsigned long pc_base;
  
  		pc_base = dev->resource.start + idev->offset;
d2a02b93c   Russell King   [ARM] Convert kma...
396
  		d = kzalloc(sizeof(struct amba_device), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
397
398
  		if (!d)
  			continue;
3f9787046   Kay Sievers   arm: bus_id -> de...
399
  		dev_set_name(&d->dev, "lm%x:%5.5lx", dev->id, idev->offset >> 12);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
402
403
404
405
406
407
408
409
410
  		d->dev.parent	= &dev->dev;
  		d->res.start	= dev->resource.start + idev->offset;
  		d->res.end	= d->res.start + SZ_4K - 1;
  		d->res.flags	= IORESOURCE_MEM;
  		d->irq[0]	= dev->irq;
  		d->irq[1]	= dev->irq;
  		d->periphid	= idev->id;
  		d->dev.platform_data = idev->platform_data;
  
  		ret = amba_device_register(d, &dev->resource);
  		if (ret) {
faa64c93a   Russell King   [ARM] fix impd1.c...
411
412
  			dev_err(&d->dev, "unable to register device: %d
  ", ret);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
413
414
415
416
417
418
419
420
421
  			kfree(d);
  		}
  	}
  
  	return 0;
  
   free_impd1:
  	if (impd1 && impd1->base)
  		iounmap(impd1->base);
b2325fe1b   Jesper Juhl   [PATCH] kfree cle...
422
  	kfree(impd1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
423
424
425
426
   release_lm:
  	release_mem_region(dev->resource.start, SZ_4K);
  	return ret;
  }
d18566376   Russell King   [ARM] Fix Integra...
427
428
429
430
431
  static int impd1_remove_one(struct device *dev, void *data)
  {
  	device_unregister(dev);
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
433
434
  static void impd1_remove(struct lm_device *dev)
  {
  	struct impd1_module *impd1 = lm_get_drvdata(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
435
  	int i;
d18566376   Russell King   [ARM] Fix Integra...
436
  	device_for_each_child(&dev->dev, NULL, impd1_remove_one);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437

d72fbdf01   Russell King   [ARM] integrator:...
438
439
  	for (i = 0; i < ARRAY_SIZE(impd1->clks); i++)
  		clkdev_drop(impd1->clks[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
  
  	lm_set_drvdata(dev, NULL);
  
  	iounmap(impd1->base);
  	kfree(impd1);
  	release_mem_region(dev->resource.start, SZ_4K);
  }
  
  static struct lm_driver impd1_driver = {
  	.drv = {
  		.name	= "impd1",
  	},
  	.probe		= impd1_probe,
  	.remove		= impd1_remove,
  };
  
  static int __init impd1_init(void)
  {
  	return lm_driver_register(&impd1_driver);
  }
  
  static void __exit impd1_exit(void)
  {
  	lm_driver_unregister(&impd1_driver);
  }
  
  module_init(impd1_init);
  module_exit(impd1_exit);
  
  MODULE_LICENSE("GPL");
  MODULE_DESCRIPTION("Integrator/IM-PD1 logic module core driver");
  MODULE_AUTHOR("Deep Blue Solutions Ltd");