2 * da9063-core.c: Device access for Dialog DA9063 modules
4 * Copyright 2012 Dialog Semiconductors Ltd.
5 * Copyright 2013 Philipp Zabel, Pengutronix
7 * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>,
8 * Michal Hajduk <michal.hajduk@diasemi.com>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/slab.h>
21 #include <linux/device.h>
22 #include <linux/delay.h>
23 #include <linux/interrupt.h>
24 #include <linux/mutex.h>
25 #include <linux/mfd/core.h>
26 #include <linux/regmap.h>
28 #include <linux/mfd/da9063/core.h>
29 #include <linux/mfd/da9063/pdata.h>
30 #include <linux/mfd/da9063/registers.h>
32 #include <linux/proc_fs.h>
33 #include <linux/kthread.h>
34 #include <linux/uaccess.h>
37 static struct resource da9063_regulators_resources
[] = {
40 .start
= DA9063_IRQ_LDO_LIM
,
41 .end
= DA9063_IRQ_LDO_LIM
,
42 .flags
= IORESOURCE_IRQ
,
46 static struct resource da9063_rtc_resources
[] = {
49 .start
= DA9063_IRQ_ALARM
,
50 .end
= DA9063_IRQ_ALARM
,
51 .flags
= IORESOURCE_IRQ
,
55 .start
= DA9063_IRQ_TICK
,
56 .end
= DA9063_IRQ_TICK
,
57 .flags
= IORESOURCE_IRQ
,
61 static struct resource da9063_onkey_resources
[] = {
63 .start
= DA9063_IRQ_ONKEY
,
64 .end
= DA9063_IRQ_ONKEY
,
65 .flags
= IORESOURCE_IRQ
,
69 static struct resource da9063_hwmon_resources
[] = {
71 .start
= DA9063_IRQ_ADC_RDY
,
72 .end
= DA9063_IRQ_ADC_RDY
,
73 .flags
= IORESOURCE_IRQ
,
78 static const struct mfd_cell da9063_devs
[] = {
80 .name
= DA9063_DRVNAME_REGULATORS
,
81 .num_resources
= ARRAY_SIZE(da9063_regulators_resources
),
82 .resources
= da9063_regulators_resources
,
85 .name
= DA9063_DRVNAME_LEDS
,
88 .name
= DA9063_DRVNAME_WATCHDOG
,
91 .name
= DA9063_DRVNAME_HWMON
,
92 .num_resources
= ARRAY_SIZE(da9063_hwmon_resources
),
93 .resources
= da9063_hwmon_resources
,
96 .name
= DA9063_DRVNAME_ONKEY
,
97 .num_resources
= ARRAY_SIZE(da9063_onkey_resources
),
98 .resources
= da9063_onkey_resources
,
101 .name
= DA9063_DRVNAME_RTC
,
102 .num_resources
= ARRAY_SIZE(da9063_rtc_resources
),
103 .resources
= da9063_rtc_resources
,
106 .name
= DA9063_DRVNAME_VIBRATION
,
110 int da9063_device_init(struct da9063
*da9063
, unsigned int irq
)
112 struct da9063_pdata
*pdata
= da9063
->dev
->platform_data
;
117 da9063
->flags
= pdata
->flags
;
118 da9063
->irq_base
= pdata
->irq_base
;
121 da9063
->irq_base
= 0;
123 da9063
->chip_irq
= irq
;
125 if (pdata
&& pdata
->init
!= NULL
) {
126 ret
= pdata
->init(da9063
);
129 "Platform initialization failed.\n");
134 ret
= regmap_read(da9063
->regmap
, DA9063_REG_CHIP_ID
, &model
);
136 dev_err(da9063
->dev
, "Cannot read chip model id.\n");
139 if (model
!= PMIC_DA9063
) {
140 dev_err(da9063
->dev
, "Invalid chip model id: 0x%02x\n", model
);
144 ret
= regmap_read(da9063
->regmap
, DA9063_REG_CHIP_VARIANT
, &revision
);
146 dev_err(da9063
->dev
, "Cannot read chip revision id.\n");
149 revision
>>= DA9063_CHIP_VARIANT_SHIFT
;
151 dev_err(da9063
->dev
, "Unknown chip revision: %d\n", revision
);
155 da9063
->model
= model
;
156 da9063
->revision
= revision
;
158 dev_info(da9063
->dev
,
159 "Device detected (model-ID: 0x%02X rev-ID: 0x%02X)\n",
162 ret
= da9063_irq_init(da9063
);
164 dev_err(da9063
->dev
, "Cannot initialize interrupts.\n");
168 ret
= mfd_add_devices(da9063
->dev
, -1, da9063_devs
,
169 ARRAY_SIZE(da9063_devs
), NULL
, da9063
->irq_base
,
172 dev_err(da9063
->dev
, "Cannot add MFD cells\n");
177 void da9063_device_exit(struct da9063
*da9063
)
179 mfd_remove_devices(da9063
->dev
);
180 da9063_irq_exit(da9063
);
183 MODULE_DESCRIPTION("PMIC driver for Dialog DA9063");
184 MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>");
185 MODULE_LICENSE("GPL");