dm vdo: add sysfs support for setting parameters and fetching stats
[linux-2.6-block.git] / drivers / mfd / mc13xxx-i2c.c
CommitLineData
d2912cb1 1// SPDX-License-Identifier: GPL-2.0-only
df3df646
MR
2/*
3 * Copyright 2009-2010 Creative Product Design
4 * Marc Reilly marc@cpdesign.com.au
df3df646
MR
5 */
6
7#include <linux/slab.h>
8#include <linux/module.h>
9#include <linux/platform_device.h>
df3df646
MR
10#include <linux/mfd/core.h>
11#include <linux/mfd/mc13xxx.h>
12#include <linux/of.h>
13#include <linux/of_device.h>
df3df646
MR
14#include <linux/i2c.h>
15#include <linux/err.h>
16
17#include "mc13xxx.h"
18
19static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
20 {
21 .name = "mc13892",
cd0f34b0 22 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
0312e024
UKK
23 }, {
24 .name = "mc34708",
25 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
df3df646
MR
26 }, {
27 /* sentinel */
28 }
29};
30MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
31
32static const struct of_device_id mc13xxx_dt_ids[] = {
33 {
34 .compatible = "fsl,mc13892",
cd0f34b0 35 .data = &mc13xxx_variant_mc13892,
0312e024
UKK
36 }, {
37 .compatible = "fsl,mc34708",
38 .data = &mc13xxx_variant_mc34708,
df3df646
MR
39 }, {
40 /* sentinel */
41 }
42};
43MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
44
18dd21ab 45static const struct regmap_config mc13xxx_regmap_i2c_config = {
df3df646
MR
46 .reg_bits = 8,
47 .val_bits = 24,
48
49 .max_register = MC13XXX_NUMREGS,
50
51 .cache_type = REGCACHE_NONE,
52};
53
10605529 54static int mc13xxx_i2c_probe(struct i2c_client *client)
df3df646 55{
df3df646 56 struct mc13xxx *mc13xxx;
df3df646
MR
57 int ret;
58
e7c706b1 59 mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
df3df646
MR
60 if (!mc13xxx)
61 return -ENOMEM;
62
63 dev_set_drvdata(&client->dev, mc13xxx);
64
db9ef449 65 mc13xxx->irq = client->irq;
df3df646 66
e7c706b1
AL
67 mc13xxx->regmap = devm_regmap_init_i2c(client,
68 &mc13xxx_regmap_i2c_config);
df3df646
MR
69 if (IS_ERR(mc13xxx->regmap)) {
70 ret = PTR_ERR(mc13xxx->regmap);
db9ef449 71 dev_err(&client->dev, "Failed to initialize regmap: %d\n", ret);
df3df646
MR
72 return ret;
73 }
74
9aab92bc 75 mc13xxx->variant = i2c_get_match_data(client);
df3df646 76
db9ef449 77 return mc13xxx_common_init(&client->dev);
df3df646
MR
78}
79
ed5c2f5f 80static void mc13xxx_i2c_remove(struct i2c_client *client)
df3df646 81{
c39cf60f 82 mc13xxx_common_exit(&client->dev);
df3df646
MR
83}
84
85static struct i2c_driver mc13xxx_i2c_driver = {
86 .id_table = mc13xxx_i2c_device_id,
87 .driver = {
df3df646
MR
88 .name = "mc13xxx",
89 .of_match_table = mc13xxx_dt_ids,
90 },
9816d859 91 .probe = mc13xxx_i2c_probe,
84449216 92 .remove = mc13xxx_i2c_remove,
df3df646
MR
93};
94
95static int __init mc13xxx_i2c_init(void)
96{
97 return i2c_add_driver(&mc13xxx_i2c_driver);
98}
99subsys_initcall(mc13xxx_i2c_init);
100
101static void __exit mc13xxx_i2c_exit(void)
102{
103 i2c_del_driver(&mc13xxx_i2c_driver);
104}
105module_exit(mc13xxx_i2c_exit);
106
107MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
108MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
109MODULE_LICENSE("GPL v2");