Merge branch 'ti-sysc-fixes' into fixes
[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>
14#include <linux/of_gpio.h>
15#include <linux/i2c.h>
16#include <linux/err.h>
17
18#include "mc13xxx.h"
19
20static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
21 {
22 .name = "mc13892",
cd0f34b0 23 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
0312e024
UKK
24 }, {
25 .name = "mc34708",
26 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
df3df646
MR
27 }, {
28 /* sentinel */
29 }
30};
31MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
32
33static const struct of_device_id mc13xxx_dt_ids[] = {
34 {
35 .compatible = "fsl,mc13892",
cd0f34b0 36 .data = &mc13xxx_variant_mc13892,
0312e024
UKK
37 }, {
38 .compatible = "fsl,mc34708",
39 .data = &mc13xxx_variant_mc34708,
df3df646
MR
40 }, {
41 /* sentinel */
42 }
43};
44MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
45
18dd21ab 46static const struct regmap_config mc13xxx_regmap_i2c_config = {
df3df646
MR
47 .reg_bits = 8,
48 .val_bits = 24,
49
50 .max_register = MC13XXX_NUMREGS,
51
52 .cache_type = REGCACHE_NONE,
53};
54
55static int mc13xxx_i2c_probe(struct i2c_client *client,
56 const struct i2c_device_id *id)
57{
df3df646 58 struct mc13xxx *mc13xxx;
df3df646
MR
59 int ret;
60
e7c706b1 61 mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
df3df646
MR
62 if (!mc13xxx)
63 return -ENOMEM;
64
65 dev_set_drvdata(&client->dev, mc13xxx);
66
db9ef449 67 mc13xxx->irq = client->irq;
df3df646 68
e7c706b1
AL
69 mc13xxx->regmap = devm_regmap_init_i2c(client,
70 &mc13xxx_regmap_i2c_config);
df3df646
MR
71 if (IS_ERR(mc13xxx->regmap)) {
72 ret = PTR_ERR(mc13xxx->regmap);
db9ef449 73 dev_err(&client->dev, "Failed to initialize regmap: %d\n", ret);
df3df646
MR
74 return ret;
75 }
76
cd0f34b0
UKK
77 if (client->dev.of_node) {
78 const struct of_device_id *of_id =
79 of_match_device(mc13xxx_dt_ids, &client->dev);
80 mc13xxx->variant = of_id->data;
81 } else {
82 mc13xxx->variant = (void *)id->driver_data;
83 }
df3df646 84
db9ef449 85 return mc13xxx_common_init(&client->dev);
df3df646
MR
86}
87
4740f73f 88static int mc13xxx_i2c_remove(struct i2c_client *client)
df3df646 89{
db9ef449 90 return mc13xxx_common_exit(&client->dev);
df3df646
MR
91}
92
93static struct i2c_driver mc13xxx_i2c_driver = {
94 .id_table = mc13xxx_i2c_device_id,
95 .driver = {
df3df646
MR
96 .name = "mc13xxx",
97 .of_match_table = mc13xxx_dt_ids,
98 },
99 .probe = mc13xxx_i2c_probe,
84449216 100 .remove = mc13xxx_i2c_remove,
df3df646
MR
101};
102
103static int __init mc13xxx_i2c_init(void)
104{
105 return i2c_add_driver(&mc13xxx_i2c_driver);
106}
107subsys_initcall(mc13xxx_i2c_init);
108
109static void __exit mc13xxx_i2c_exit(void)
110{
111 i2c_del_driver(&mc13xxx_i2c_driver);
112}
113module_exit(mc13xxx_i2c_exit);
114
115MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
116MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
117MODULE_LICENSE("GPL v2");