2 * Core driver for HTC PASIC3 LED/DS1WM chip.
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.
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
15 #include <linux/ds1wm.h>
16 #include <linux/gpio.h>
18 #include <linux/irq.h>
19 #include <linux/interrupt.h>
20 #include <linux/mfd/htc-pasic3.h>
22 #include <asm/arch/pxa-regs.h>
25 void __iomem *mapping;
26 unsigned int bus_shift;
27 struct platform_device *ds1wm_pdev;
28 struct platform_device *led_pdev;
35 #define READ_MODE 0x80
38 * write to a secondary register on the PASIC3
40 void pasic3_write_register(struct device *dev, u32 reg, u8 val)
42 struct pasic3_data *asic = dev->driver_data;
43 int bus_shift = asic->bus_shift;
44 void __iomem *addr = asic->mapping + (REG_ADDR << bus_shift);
45 void __iomem *data = asic->mapping + (REG_DATA << bus_shift);
47 __raw_writeb(~READ_MODE & reg, addr);
48 __raw_writeb(val, data);
50 EXPORT_SYMBOL(pasic3_write_register); /* for leds-pasic3 */
53 * read from a secondary register on the PASIC3
55 u8 pasic3_read_register(struct device *dev, u32 reg)
57 struct pasic3_data *asic = dev->driver_data;
58 int bus_shift = asic->bus_shift;
59 void __iomem *addr = asic->mapping + (REG_ADDR << bus_shift);
60 void __iomem *data = asic->mapping + (REG_DATA << bus_shift);
62 __raw_writeb(READ_MODE | reg, addr);
63 return __raw_readb(data);
65 EXPORT_SYMBOL(pasic3_read_register); /* for leds-pasic3 */
71 static int led_device_add(struct device *pasic3_dev,
72 const struct pasic3_leds_machinfo *pdata)
74 struct pasic3_data *asic = pasic3_dev->driver_data;
75 struct platform_device *pdev;
78 pdev = platform_device_alloc("pasic3-led", -1);
80 dev_dbg(pasic3_dev, "failed to allocate LED platform device\n");
84 ret = platform_device_add_data(pdev, pdata,
85 sizeof(struct pasic3_leds_machinfo));
87 dev_dbg(pasic3_dev, "failed to add LED platform data\n");
91 pdev->dev.parent = pasic3_dev;
92 ret = platform_device_add(pdev);
94 dev_dbg(pasic3_dev, "failed to add LED platform device\n");
98 asic->led_pdev = pdev;
102 platform_device_put(pdev);
110 static void ds1wm_enable(struct platform_device *pdev)
112 struct device *dev = pdev->dev.parent;
115 c = pasic3_read_register(dev, 0x28);
116 pasic3_write_register(dev, 0x28, c & 0x7f);
118 dev_dbg(dev, "DS1WM OWM_EN low (active) %02x\n", c & 0x7f);
121 static void ds1wm_disable(struct platform_device *pdev)
123 struct device *dev = pdev->dev.parent;
126 c = pasic3_read_register(dev, 0x28);
127 pasic3_write_register(dev, 0x28, c | 0x80);
129 dev_dbg(dev, "DS1WM OWM_EN high (inactive) %02x\n", c | 0x80);
132 static struct ds1wm_platform_data ds1wm_pdata = {
134 .enable = ds1wm_enable,
135 .disable = ds1wm_disable,
138 static int ds1wm_device_add(struct device *pasic3_dev, int bus_shift)
140 struct pasic3_data *asic = pasic3_dev->driver_data;
141 struct platform_device *pdev;
144 pdev = platform_device_alloc("ds1wm", -1);
146 dev_dbg(pasic3_dev, "failed to allocate DS1WM platform device\n");
150 ret = platform_device_add_resources(pdev, pdev->resource,
151 pdev->num_resources);
153 dev_dbg(pasic3_dev, "failed to add DS1WM resources\n");
157 ds1wm_pdata.bus_shift = asic->bus_shift;
158 ret = platform_device_add_data(pdev, &ds1wm_pdata,
159 sizeof(struct ds1wm_platform_data));
161 dev_dbg(pasic3_dev, "failed to add DS1WM platform data\n");
165 pdev->dev.parent = pasic3_dev;
166 ret = platform_device_add(pdev);
168 dev_dbg(pasic3_dev, "failed to add DS1WM platform device\n");
172 asic->ds1wm_pdev = pdev;
176 platform_device_put(pdev);
180 static int __init pasic3_probe(struct platform_device *pdev)
182 struct pasic3_platform_data *pdata = pdev->dev.platform_data;
183 struct device *dev = &pdev->dev;
184 struct pasic3_data *asic;
188 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
192 if (!request_mem_region(r->start, r->end - r->start + 1, "pasic3"))
195 asic = kzalloc(sizeof(struct pasic3_data), GFP_KERNEL);
199 platform_set_drvdata(pdev, asic);
201 if (pdata && pdata->bus_shift)
202 asic->bus_shift = pdata->bus_shift;
206 asic->mapping = ioremap(r->start, r->end - r->start + 1);
207 if (!asic->mapping) {
208 dev_err(dev, "couldn't ioremap PASIC3\n");
213 ret = ds1wm_device_add(dev, asic->bus_shift);
215 dev_warn(dev, "failed to register DS1WM\n");
217 if (pdata->led_pdata) {
218 ret = led_device_add(dev, pdata->led_pdata);
220 dev_warn(dev, "failed to register LED device\n");
226 static int pasic3_remove(struct platform_device *pdev)
228 struct pasic3_data *asic = platform_get_drvdata(pdev);
232 platform_device_unregister(asic->led_pdev);
233 if (asic->ds1wm_pdev)
234 platform_device_unregister(asic->ds1wm_pdev);
236 iounmap(asic->mapping);
237 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
238 release_mem_region(r->start, r->end - r->start + 1);
243 static struct platform_driver pasic3_driver = {
247 .remove = pasic3_remove,
250 static int __init pasic3_base_init(void)
252 return platform_driver_probe(&pasic3_driver, pasic3_probe);
255 static void __exit pasic3_base_exit(void)
257 platform_driver_unregister(&pasic3_driver);
260 module_init(pasic3_base_init);
261 module_exit(pasic3_base_exit);
263 MODULE_AUTHOR("Philipp Zabel <philipp.zabel@gmail.com>");
264 MODULE_DESCRIPTION("Core driver for HTC PASIC3");
265 MODULE_LICENSE("GPL");