Commit | Line | Data |
---|---|---|
8e685483 KG |
1 | /* |
2 | * da9063-core.c: Device access for Dialog DA9063 modules | |
3 | * | |
4 | * Copyright 2012 Dialog Semiconductors Ltd. | |
5 | * Copyright 2013 Philipp Zabel, Pengutronix | |
6 | * | |
7 | * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>, | |
8 | * Michal Hajduk <michal.hajduk@diasemi.com> | |
9 | * | |
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. | |
14 | * | |
15 | */ | |
16 | ||
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> | |
27 | ||
28 | #include <linux/mfd/da9063/core.h> | |
29 | #include <linux/mfd/da9063/pdata.h> | |
30 | #include <linux/mfd/da9063/registers.h> | |
31 | ||
32 | #include <linux/proc_fs.h> | |
33 | #include <linux/kthread.h> | |
34 | #include <linux/uaccess.h> | |
35 | ||
36 | ||
37 | static struct mfd_cell da9063_devs[] = { | |
38 | { | |
39 | .name = DA9063_DRVNAME_REGULATORS, | |
40 | }, | |
41 | { | |
42 | .name = DA9063_DRVNAME_LEDS, | |
43 | }, | |
44 | { | |
45 | .name = DA9063_DRVNAME_WATCHDOG, | |
46 | }, | |
47 | { | |
48 | .name = DA9063_DRVNAME_HWMON, | |
49 | }, | |
50 | { | |
51 | .name = DA9063_DRVNAME_ONKEY, | |
52 | }, | |
53 | { | |
54 | .name = DA9063_DRVNAME_RTC, | |
55 | }, | |
56 | { | |
57 | .name = DA9063_DRVNAME_VIBRATION, | |
58 | }, | |
59 | }; | |
60 | ||
61 | int da9063_device_init(struct da9063 *da9063, unsigned int irq) | |
62 | { | |
63 | struct da9063_pdata *pdata = da9063->dev->platform_data; | |
64 | int model, revision; | |
65 | int ret; | |
66 | ||
67 | if (pdata) { | |
68 | da9063->flags = pdata->flags; | |
69 | da9063->irq_base = pdata->irq_base; | |
70 | } else { | |
71 | da9063->flags = 0; | |
72 | da9063->irq_base = 0; | |
73 | } | |
74 | da9063->chip_irq = irq; | |
75 | ||
76 | if (pdata && pdata->init != NULL) { | |
77 | ret = pdata->init(da9063); | |
78 | if (ret != 0) { | |
79 | dev_err(da9063->dev, | |
80 | "Platform initialization failed.\n"); | |
81 | return ret; | |
82 | } | |
83 | } | |
84 | ||
85 | ret = regmap_read(da9063->regmap, DA9063_REG_CHIP_ID, &model); | |
86 | if (ret < 0) { | |
87 | dev_err(da9063->dev, "Cannot read chip model id.\n"); | |
88 | return -EIO; | |
89 | } | |
90 | if (model != PMIC_DA9063) { | |
91 | dev_err(da9063->dev, "Invalid chip model id: 0x%02x\n", model); | |
92 | return -ENODEV; | |
93 | } | |
94 | ||
95 | ret = regmap_read(da9063->regmap, DA9063_REG_CHIP_VARIANT, &revision); | |
96 | if (ret < 0) { | |
97 | dev_err(da9063->dev, "Cannot read chip revision id.\n"); | |
98 | return -EIO; | |
99 | } | |
100 | revision >>= DA9063_CHIP_VARIANT_SHIFT; | |
101 | if (revision != 3) { | |
102 | dev_err(da9063->dev, "Unknown chip revision: %d\n", revision); | |
103 | return -ENODEV; | |
104 | } | |
105 | ||
106 | da9063->model = model; | |
107 | da9063->revision = revision; | |
108 | ||
109 | dev_info(da9063->dev, | |
110 | "Device detected (model-ID: 0x%02X rev-ID: 0x%02X)\n", | |
111 | model, revision); | |
112 | ||
113 | ret = mfd_add_devices(da9063->dev, -1, da9063_devs, | |
114 | ARRAY_SIZE(da9063_devs), NULL, da9063->irq_base, | |
115 | NULL); | |
116 | if (ret) | |
117 | dev_err(da9063->dev, "Cannot add MFD cells\n"); | |
118 | ||
119 | return ret; | |
120 | } | |
121 | ||
122 | void da9063_device_exit(struct da9063 *da9063) | |
123 | { | |
124 | mfd_remove_devices(da9063->dev); | |
125 | } | |
126 | ||
127 | MODULE_DESCRIPTION("PMIC driver for Dialog DA9063"); | |
128 | MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>, Michal Hajduk <michal.hajduk@diasemi.com>"); | |
129 | MODULE_LICENSE("GPL"); |