blob: 5adb2e3dca8d3f601847ec28b59f398708ea93c6 [file] [log] [blame]
Matt Porter037b60f2014-03-11 19:33:54 -04001/*
2 * Broadcom BCM590xx PMU
3 *
4 * Copyright 2014 Linaro Limited
5 * Author: Matt Porter <mporter@linaro.org>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/err.h>
14#include <linux/i2c.h>
15#include <linux/init.h>
16#include <linux/mfd/bcm590xx.h>
17#include <linux/mfd/core.h>
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/of.h>
21#include <linux/of_device.h>
22#include <linux/regmap.h>
23#include <linux/slab.h>
24
25static const struct mfd_cell bcm590xx_devs[] = {
26 {
27 .name = "bcm590xx-vregs",
28 },
29};
30
31static const struct regmap_config bcm590xx_regmap_config = {
32 .reg_bits = 8,
33 .val_bits = 8,
34 .max_register = BCM590XX_MAX_REGISTER,
35 .cache_type = REGCACHE_RBTREE,
36};
37
38static int bcm590xx_i2c_probe(struct i2c_client *i2c,
39 const struct i2c_device_id *id)
40{
41 struct bcm590xx *bcm590xx;
42 int ret;
43
44 bcm590xx = devm_kzalloc(&i2c->dev, sizeof(*bcm590xx), GFP_KERNEL);
45 if (!bcm590xx)
46 return -ENOMEM;
47
48 i2c_set_clientdata(i2c, bcm590xx);
49 bcm590xx->dev = &i2c->dev;
50 bcm590xx->i2c_client = i2c;
51
52 bcm590xx->regmap = devm_regmap_init_i2c(i2c, &bcm590xx_regmap_config);
53 if (IS_ERR(bcm590xx->regmap)) {
54 ret = PTR_ERR(bcm590xx->regmap);
55 dev_err(&i2c->dev, "regmap initialization failed: %d\n", ret);
56 return ret;
57 }
58
59 ret = mfd_add_devices(&i2c->dev, -1, bcm590xx_devs,
60 ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL);
61 if (ret < 0)
62 dev_err(&i2c->dev, "failed to add sub-devices: %d\n", ret);
63
64 return ret;
65}
66
Axel Lin2b29ff72014-03-31 21:32:37 +080067static int bcm590xx_i2c_remove(struct i2c_client *i2c)
68{
69 mfd_remove_devices(&i2c->dev);
70 return 0;
71}
72
Matt Porter037b60f2014-03-11 19:33:54 -040073static const struct of_device_id bcm590xx_of_match[] = {
74 { .compatible = "brcm,bcm59056" },
75 { }
76};
Axel Lin3827c512014-03-15 09:24:50 +080077MODULE_DEVICE_TABLE(of, bcm590xx_of_match);
Matt Porter037b60f2014-03-11 19:33:54 -040078
79static const struct i2c_device_id bcm590xx_i2c_id[] = {
80 { "bcm59056" },
81 { }
82};
83MODULE_DEVICE_TABLE(i2c, bcm590xx_i2c_id);
84
85static struct i2c_driver bcm590xx_i2c_driver = {
86 .driver = {
87 .name = "bcm590xx",
88 .owner = THIS_MODULE,
89 .of_match_table = of_match_ptr(bcm590xx_of_match),
90 },
91 .probe = bcm590xx_i2c_probe,
Axel Lin2b29ff72014-03-31 21:32:37 +080092 .remove = bcm590xx_i2c_remove,
Matt Porter037b60f2014-03-11 19:33:54 -040093 .id_table = bcm590xx_i2c_id,
94};
95module_i2c_driver(bcm590xx_i2c_driver);
96
97MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
98MODULE_DESCRIPTION("BCM590xx multi-function driver");
99MODULE_LICENSE("GPL v2");
100MODULE_ALIAS("platform:bcm590xx");