1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2009-2010 Creative Product Design
4 * Marc Reilly marc@cpdesign.com.au
7 #include <linux/slab.h>
8 #include <linux/module.h>
9 #include <linux/platform_device.h>
10 #include <linux/mfd/core.h>
11 #include <linux/mfd/mc13xxx.h>
13 #include <linux/of_device.h>
14 #include <linux/i2c.h>
15 #include <linux/err.h>
19 static const struct i2c_device_id mc13xxx_i2c_device_id
[] = {
22 .driver_data
= (kernel_ulong_t
)&mc13xxx_variant_mc13892
,
25 .driver_data
= (kernel_ulong_t
)&mc13xxx_variant_mc34708
,
30 MODULE_DEVICE_TABLE(i2c
, mc13xxx_i2c_device_id
);
32 static const struct of_device_id mc13xxx_dt_ids
[] = {
34 .compatible
= "fsl,mc13892",
35 .data
= &mc13xxx_variant_mc13892
,
37 .compatible
= "fsl,mc34708",
38 .data
= &mc13xxx_variant_mc34708
,
43 MODULE_DEVICE_TABLE(of
, mc13xxx_dt_ids
);
45 static const struct regmap_config mc13xxx_regmap_i2c_config
= {
49 .max_register
= MC13XXX_NUMREGS
,
51 .cache_type
= REGCACHE_NONE
,
54 static int mc13xxx_i2c_probe(struct i2c_client
*client
)
56 struct mc13xxx
*mc13xxx
;
59 mc13xxx
= devm_kzalloc(&client
->dev
, sizeof(*mc13xxx
), GFP_KERNEL
);
63 dev_set_drvdata(&client
->dev
, mc13xxx
);
65 mc13xxx
->irq
= client
->irq
;
67 mc13xxx
->regmap
= devm_regmap_init_i2c(client
,
68 &mc13xxx_regmap_i2c_config
);
69 if (IS_ERR(mc13xxx
->regmap
)) {
70 ret
= PTR_ERR(mc13xxx
->regmap
);
71 dev_err(&client
->dev
, "Failed to initialize regmap: %d\n", ret
);
75 mc13xxx
->variant
= i2c_get_match_data(client
);
77 return mc13xxx_common_init(&client
->dev
);
80 static void mc13xxx_i2c_remove(struct i2c_client
*client
)
82 mc13xxx_common_exit(&client
->dev
);
85 static struct i2c_driver mc13xxx_i2c_driver
= {
86 .id_table
= mc13xxx_i2c_device_id
,
89 .of_match_table
= mc13xxx_dt_ids
,
91 .probe
= mc13xxx_i2c_probe
,
92 .remove
= mc13xxx_i2c_remove
,
95 static int __init
mc13xxx_i2c_init(void)
97 return i2c_add_driver(&mc13xxx_i2c_driver
);
99 subsys_initcall(mc13xxx_i2c_init
);
101 static void __exit
mc13xxx_i2c_exit(void)
103 i2c_del_driver(&mc13xxx_i2c_driver
);
105 module_exit(mc13xxx_i2c_exit
);
107 MODULE_DESCRIPTION("i2c driver for Freescale MC13XXX PMIC");
108 MODULE_AUTHOR("Marc Reilly <marc@cpdesign.com.au");
109 MODULE_LICENSE("GPL v2");