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/gpio.h>
17 #include <linux/irq.h>
18 #include <linux/interrupt.h>
19 #include <linux/mfd/core.h>
20 #include <linux/mfd/ds1wm.h>
21 #include <linux/mfd/htc-pasic3.h>
22 #include <linux/slab.h>
25 void __iomem
*mapping
;
26 unsigned int bus_shift
;
32 #define READ_MODE 0x80
35 * write to a secondary register on the PASIC3
37 void pasic3_write_register(struct device
*dev
, u32 reg
, u8 val
)
39 struct pasic3_data
*asic
= dev_get_drvdata(dev
);
40 int bus_shift
= asic
->bus_shift
;
41 void __iomem
*addr
= asic
->mapping
+ (REG_ADDR
<< bus_shift
);
42 void __iomem
*data
= asic
->mapping
+ (REG_DATA
<< bus_shift
);
44 __raw_writeb(~READ_MODE
& reg
, addr
);
45 __raw_writeb(val
, data
);
47 EXPORT_SYMBOL(pasic3_write_register
); /* for leds-pasic3 */
50 * read from a secondary register on the PASIC3
52 u8
pasic3_read_register(struct device
*dev
, u32 reg
)
54 struct pasic3_data
*asic
= dev_get_drvdata(dev
);
55 int bus_shift
= asic
->bus_shift
;
56 void __iomem
*addr
= asic
->mapping
+ (REG_ADDR
<< bus_shift
);
57 void __iomem
*data
= asic
->mapping
+ (REG_DATA
<< bus_shift
);
59 __raw_writeb(READ_MODE
| reg
, addr
);
60 return __raw_readb(data
);
62 EXPORT_SYMBOL(pasic3_read_register
); /* for leds-pasic3 */
68 static struct mfd_cell led_cell __initdata
= {
69 .name
= "leds-pasic3",
76 static int ds1wm_enable(struct platform_device
*pdev
)
78 struct device
*dev
= pdev
->dev
.parent
;
81 c
= pasic3_read_register(dev
, 0x28);
82 pasic3_write_register(dev
, 0x28, c
& 0x7f);
84 dev_dbg(dev
, "DS1WM OWM_EN low (active) %02x\n", c
& 0x7f);
88 static int ds1wm_disable(struct platform_device
*pdev
)
90 struct device
*dev
= pdev
->dev
.parent
;
93 c
= pasic3_read_register(dev
, 0x28);
94 pasic3_write_register(dev
, 0x28, c
| 0x80);
96 dev_dbg(dev
, "DS1WM OWM_EN high (inactive) %02x\n", c
| 0x80);
100 static struct ds1wm_driver_data ds1wm_pdata
= {
102 .reset_recover_delay
= 1,
105 static struct resource ds1wm_resources
[] __initdata
= {
108 .flags
= IORESOURCE_MEM
,
113 .flags
= IORESOURCE_IRQ
,
117 static const struct mfd_cell ds1wm_cell __initconst
= {
119 .enable
= ds1wm_enable
,
120 .disable
= ds1wm_disable
,
121 .platform_data
= &ds1wm_pdata
,
122 .pdata_size
= sizeof(ds1wm_pdata
),
124 .resources
= ds1wm_resources
,
127 static int __init
pasic3_probe(struct platform_device
*pdev
)
129 struct pasic3_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
130 struct device
*dev
= &pdev
->dev
;
131 struct pasic3_data
*asic
;
136 r
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
138 ds1wm_resources
[1].flags
= IORESOURCE_IRQ
| (r
->flags
&
139 (IORESOURCE_IRQ_HIGHEDGE
| IORESOURCE_IRQ_LOWEDGE
));
143 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
147 if (!request_mem_region(r
->start
, resource_size(r
), "pasic3"))
150 asic
= devm_kzalloc(dev
, sizeof(struct pasic3_data
), GFP_KERNEL
);
154 platform_set_drvdata(pdev
, asic
);
156 asic
->mapping
= ioremap(r
->start
, resource_size(r
));
157 if (!asic
->mapping
) {
158 dev_err(dev
, "couldn't ioremap PASIC3\n");
162 /* calculate bus shift from mem resource */
163 asic
->bus_shift
= (resource_size(r
) - 5) >> 3;
165 if (pdata
&& pdata
->clock_rate
) {
166 ds1wm_pdata
.clock_rate
= pdata
->clock_rate
;
167 /* the first 5 PASIC3 registers control the DS1WM */
168 ds1wm_resources
[0].end
= (5 << asic
->bus_shift
) - 1;
169 ret
= mfd_add_devices(&pdev
->dev
, pdev
->id
,
170 &ds1wm_cell
, 1, r
, irq
, NULL
);
172 dev_warn(dev
, "failed to register DS1WM\n");
175 if (pdata
&& pdata
->led_pdata
) {
176 led_cell
.platform_data
= pdata
->led_pdata
;
177 led_cell
.pdata_size
= sizeof(struct pasic3_leds_machinfo
);
178 ret
= mfd_add_devices(&pdev
->dev
, pdev
->id
, &led_cell
, 1, r
,
181 dev_warn(dev
, "failed to register LED device\n");
187 static int pasic3_remove(struct platform_device
*pdev
)
189 struct pasic3_data
*asic
= platform_get_drvdata(pdev
);
192 mfd_remove_devices(&pdev
->dev
);
194 iounmap(asic
->mapping
);
195 r
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
196 release_mem_region(r
->start
, resource_size(r
));
200 MODULE_ALIAS("platform:pasic3");
202 static struct platform_driver pasic3_driver
= {
206 .remove
= pasic3_remove
,
209 module_platform_driver_probe(pasic3_driver
, pasic3_probe
);
211 MODULE_AUTHOR("Philipp Zabel <philipp.zabel@gmail.com>");
212 MODULE_DESCRIPTION("Core driver for HTC PASIC3");
213 MODULE_LICENSE("GPL");