blob: fb937f66277e59ab5bae6249fc92b867868b9877 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Marc Reillydf3df642012-04-01 16:41:39 +10002/*
3 * Copyright 2009-2010 Creative Product Design
4 * Marc Reilly marc@cpdesign.com.au
Marc Reillydf3df642012-04-01 16:41:39 +10005 */
6
7#include <linux/slab.h>
8#include <linux/module.h>
9#include <linux/platform_device.h>
Marc Reillydf3df642012-04-01 16:41:39 +100010#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",
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000023 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
Marc Reillydf3df642012-04-01 16:41:39 +100024 }, {
Uwe Kleine-König0312e022012-07-12 09:57:53 +000025 .name = "mc34708",
26 .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc34708,
Marc Reillydf3df642012-04-01 16:41:39 +100027 }, {
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",
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000036 .data = &mc13xxx_variant_mc13892,
Marc Reillydf3df642012-04-01 16:41:39 +100037 }, {
Uwe Kleine-König0312e022012-07-12 09:57:53 +000038 .compatible = "fsl,mc34708",
39 .data = &mc13xxx_variant_mc34708,
Marc Reillydf3df642012-04-01 16:41:39 +100040 }, {
41 /* sentinel */
42 }
43};
44MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
45
Krzysztof Kozlowski18dd21a2015-01-05 10:01:26 +010046static const struct regmap_config mc13xxx_regmap_i2c_config = {
Marc Reillydf3df642012-04-01 16:41:39 +100047 .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{
Marc Reillydf3df642012-04-01 16:41:39 +100058 struct mc13xxx *mc13xxx;
Marc Reillydf3df642012-04-01 16:41:39 +100059 int ret;
60
Axel Line7c706b2012-06-29 15:14:36 +020061 mc13xxx = devm_kzalloc(&client->dev, sizeof(*mc13xxx), GFP_KERNEL);
Marc Reillydf3df642012-04-01 16:41:39 +100062 if (!mc13xxx)
63 return -ENOMEM;
64
65 dev_set_drvdata(&client->dev, mc13xxx);
66
Alexander Shiyandb9ef442013-12-14 17:03:12 +040067 mc13xxx->irq = client->irq;
Marc Reillydf3df642012-04-01 16:41:39 +100068
Axel Line7c706b2012-06-29 15:14:36 +020069 mc13xxx->regmap = devm_regmap_init_i2c(client,
70 &mc13xxx_regmap_i2c_config);
Marc Reillydf3df642012-04-01 16:41:39 +100071 if (IS_ERR(mc13xxx->regmap)) {
72 ret = PTR_ERR(mc13xxx->regmap);
Alexander Shiyandb9ef442013-12-14 17:03:12 +040073 dev_err(&client->dev, "Failed to initialize regmap: %d\n", ret);
Marc Reillydf3df642012-04-01 16:41:39 +100074 return ret;
75 }
76
Uwe Kleine-Königcd0f34b2012-07-12 09:57:52 +000077 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 }
Marc Reillydf3df642012-04-01 16:41:39 +100084
Alexander Shiyandb9ef442013-12-14 17:03:12 +040085 return mc13xxx_common_init(&client->dev);
Marc Reillydf3df642012-04-01 16:41:39 +100086}
87
Bill Pemberton4740f732012-11-19 13:26:01 -050088static int mc13xxx_i2c_remove(struct i2c_client *client)
Marc Reillydf3df642012-04-01 16:41:39 +100089{
Uwe Kleine-Königc39cf602021-10-12 17:39:33 +020090 mc13xxx_common_exit(&client->dev);
91 return 0;
Marc Reillydf3df642012-04-01 16:41:39 +100092}
93
94static struct i2c_driver mc13xxx_i2c_driver = {
95 .id_table = mc13xxx_i2c_device_id,
96 .driver = {
Marc Reillydf3df642012-04-01 16:41:39 +100097 .name = "mc13xxx",
98 .of_match_table = mc13xxx_dt_ids,
99 },
100 .probe = mc13xxx_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500101 .remove = mc13xxx_i2c_remove,
Marc Reillydf3df642012-04-01 16:41:39 +1000102};
103
104static int __init mc13xxx_i2c_init(void)
105{
106 return i2c_add_driver(&mc13xxx_i2c_driver);
107}
108subsys_initcall(mc13xxx_i2c_init);
109
110static void __exit mc13xxx_i2c_exit(void)
111{
112 i2c_del_driver(&mc13xxx_i2c_driver);
113}
114module_exit(mc13xxx_i2c_exit);
115
116MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
117MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
118MODULE_LICENSE("GPL v2");