Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Broadcom BCM590xx PMU
0004  *
0005  * Copyright 2014 Linaro Limited
0006  * Author: Matt Porter <mporter@linaro.org>
0007  */
0008 
0009 #include <linux/err.h>
0010 #include <linux/i2c.h>
0011 #include <linux/init.h>
0012 #include <linux/mfd/bcm590xx.h>
0013 #include <linux/mfd/core.h>
0014 #include <linux/module.h>
0015 #include <linux/moduleparam.h>
0016 #include <linux/of.h>
0017 #include <linux/of_device.h>
0018 #include <linux/regmap.h>
0019 #include <linux/slab.h>
0020 
0021 static const struct mfd_cell bcm590xx_devs[] = {
0022     {
0023         .name = "bcm590xx-vregs",
0024     },
0025 };
0026 
0027 static const struct regmap_config bcm590xx_regmap_config_pri = {
0028     .reg_bits   = 8,
0029     .val_bits   = 8,
0030     .max_register   = BCM590XX_MAX_REGISTER_PRI,
0031     .cache_type = REGCACHE_RBTREE,
0032 };
0033 
0034 static const struct regmap_config bcm590xx_regmap_config_sec = {
0035     .reg_bits   = 8,
0036     .val_bits   = 8,
0037     .max_register   = BCM590XX_MAX_REGISTER_SEC,
0038     .cache_type = REGCACHE_RBTREE,
0039 };
0040 
0041 static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri,
0042                   const struct i2c_device_id *id)
0043 {
0044     struct bcm590xx *bcm590xx;
0045     int ret;
0046 
0047     bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL);
0048     if (!bcm590xx)
0049         return -ENOMEM;
0050 
0051     i2c_set_clientdata(i2c_pri, bcm590xx);
0052     bcm590xx->dev = &i2c_pri->dev;
0053     bcm590xx->i2c_pri = i2c_pri;
0054 
0055     bcm590xx->regmap_pri = devm_regmap_init_i2c(i2c_pri,
0056                          &bcm590xx_regmap_config_pri);
0057     if (IS_ERR(bcm590xx->regmap_pri)) {
0058         ret = PTR_ERR(bcm590xx->regmap_pri);
0059         dev_err(&i2c_pri->dev, "primary regmap init failed: %d\n", ret);
0060         return ret;
0061     }
0062 
0063     /* Secondary I2C slave address is the base address with A(2) asserted */
0064     bcm590xx->i2c_sec = i2c_new_dummy_device(i2c_pri->adapter,
0065                       i2c_pri->addr | BIT(2));
0066     if (IS_ERR(bcm590xx->i2c_sec)) {
0067         dev_err(&i2c_pri->dev, "failed to add secondary I2C device\n");
0068         return PTR_ERR(bcm590xx->i2c_sec);
0069     }
0070     i2c_set_clientdata(bcm590xx->i2c_sec, bcm590xx);
0071 
0072     bcm590xx->regmap_sec = devm_regmap_init_i2c(bcm590xx->i2c_sec,
0073                         &bcm590xx_regmap_config_sec);
0074     if (IS_ERR(bcm590xx->regmap_sec)) {
0075         ret = PTR_ERR(bcm590xx->regmap_sec);
0076         dev_err(&bcm590xx->i2c_sec->dev,
0077             "secondary regmap init failed: %d\n", ret);
0078         goto err;
0079     }
0080 
0081     ret = devm_mfd_add_devices(&i2c_pri->dev, -1, bcm590xx_devs,
0082                    ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL);
0083     if (ret < 0) {
0084         dev_err(&i2c_pri->dev, "failed to add sub-devices: %d\n", ret);
0085         goto err;
0086     }
0087 
0088     return 0;
0089 
0090 err:
0091     i2c_unregister_device(bcm590xx->i2c_sec);
0092     return ret;
0093 }
0094 
0095 static const struct of_device_id bcm590xx_of_match[] = {
0096     { .compatible = "brcm,bcm59056" },
0097     { }
0098 };
0099 MODULE_DEVICE_TABLE(of, bcm590xx_of_match);
0100 
0101 static const struct i2c_device_id bcm590xx_i2c_id[] = {
0102     { "bcm59056" },
0103     { }
0104 };
0105 MODULE_DEVICE_TABLE(i2c, bcm590xx_i2c_id);
0106 
0107 static struct i2c_driver bcm590xx_i2c_driver = {
0108     .driver = {
0109            .name = "bcm590xx",
0110            .of_match_table = bcm590xx_of_match,
0111     },
0112     .probe = bcm590xx_i2c_probe,
0113     .id_table = bcm590xx_i2c_id,
0114 };
0115 module_i2c_driver(bcm590xx_i2c_driver);
0116 
0117 MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
0118 MODULE_DESCRIPTION("BCM590xx multi-function driver");
0119 MODULE_LICENSE("GPL v2");