hh.org updates
[hh.org.git] / arch / arm / mach-pxa / magician / magician_ds1wm.c
blob25241fff5b8f3e14da7ab20323fd4313110be685
1 /*
2 * magician_ds1wm.c - HTC Magician DS1WM-in-AIC3 driver
4 * Copyright (C) 2006 Philipp Zabel <philipp.zabel@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 */
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
15 #include <asm/arch/pxa-regs.h>
16 #include <linux/io.h>
18 #include <linux/irq.h>
19 #include <linux/interrupt.h>
21 #include <linux/clk.h>
22 #include <asm/arch/clock.h>
23 #include "../../../../drivers/w1/masters/ds1wm.h"
25 unsigned int __iomem *iobase;
27 static int read_register(int reg)
29 u16 *addr=((u16 *)(iobase+5));
30 u8 *data=((u8 *)(iobase+6));
32 *addr |= 0x80; /* read mode */
33 *addr = (*addr & 0xff80) | (reg & 0x7f);
35 barrier();
36 return *data;
39 static void write_register(int reg, int val)
41 u16 *addr=((u16 *)(iobase+5));
42 u16 *data=((u16 *)(iobase+6));
44 *addr = (*addr & 0xff80) | (reg & 0x7f);
45 *addr &= 0xff7f; /* write mode */
47 barrier();
48 *data = (*data & 0xff00) | (val & 0xff);
51 static struct resource magician_ds1wm_resources[] = {
52 [0] = {
53 .start = PXA_CS2_PHYS,
54 .end = PXA_CS2_PHYS + 0x10,
55 .flags = IORESOURCE_MEM,
57 [1] = {
58 .start = IRQ_GPIO(107),
59 .end = IRQ_GPIO(107),
60 .flags = IORESOURCE_IRQ,
64 static struct ds1wm_platform_data magician_ds1wm_platform_data = {
65 .bus_shift = 2,
68 static struct platform_device *magician_ds1wm;
69 #if 0
70 = {
71 .name = "ds1wm",
72 .id = -1,
73 .num_resources = ARRAY_SIZE(magician_ds1wm_resources),
74 .resource = magician_ds1wm_resources,
75 .dev = {
76 .platform_data = magician_ds1wm_platform_data,
79 #endif
81 static void magician_ds1wm_enable(struct clk *clock)
83 int c;
85 /* I don't know how to enable the 4MHz OWM clock here */
87 c = read_register(0x28);
88 write_register(0x28, c & 0x7f);
90 printk ("magician_ds1wm: OWM_EN low (active) %02x\n", c & 0x7f);
93 static void magician_ds1wm_disable(struct clk *clock)
95 int c;
96 c = read_register(0x28);
97 write_register(0x28, c | 0x80);
99 printk ("magician_ds1wm: OWM_EN high (inactive) %02x\n", c | 0x80);
101 /* I don't know how to disable the 4MHz OWM clock here */
104 static struct clk ds1wm_clk = {
105 .name = "ds1wm",
106 .rate = 4000000,
107 .parent = NULL,
108 .enable = magician_ds1wm_enable,
109 .disable = magician_ds1wm_disable,
112 static int __devinit magician_ds1wm_init(void)
114 int ret;
116 printk("Magician DS1WM driver\n");
117 iobase = ioremap_nocache(PXA_CS2_PHYS, 0x18); // map PASIC3 for EGPIO registers
118 set_irq_type (IRQ_GPIO(107), IRQT_RISING);
120 if (clk_register(&ds1wm_clk) < 0)
121 printk(KERN_ERR "failed to register DS1WM clock\n");
123 magician_ds1wm = platform_device_alloc("ds1wm", -1);
124 if (!magician_ds1wm) {
125 printk("magician_ds1wm: failed to allocate platform device\n");
126 ret = -ENOMEM;
127 goto exit_unmap;
130 magician_ds1wm->num_resources = ARRAY_SIZE(magician_ds1wm_resources);
131 magician_ds1wm->resource = magician_ds1wm_resources;
132 magician_ds1wm->dev.platform_data = &magician_ds1wm_platform_data;
133 ret = platform_device_add(magician_ds1wm);
135 if (ret) {
136 platform_device_put(magician_ds1wm);
137 printk("magician_ds1wm: failed to add platform device\n");
140 return ret;
142 exit_unmap:
143 iounmap((void __iomem *)iobase);
144 return ret;
147 static void __devexit magician_ds1wm_exit(void)
149 platform_device_unregister(magician_ds1wm);
150 iounmap((void __iomem *)iobase);
153 MODULE_AUTHOR("Philipp Zabel <philipp.zabel@gmail.com>");
154 MODULE_DESCRIPTION("DS1WM driver");
155 MODULE_LICENSE("GPL");
157 module_init(magician_ds1wm_init);
158 module_exit(magician_ds1wm_exit);