Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Arizona-i2c.c  --  Arizona I2C bus interface
0004  *
0005  * Copyright 2012 Wolfson Microelectronics plc
0006  *
0007  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
0008  */
0009 
0010 #include <linux/err.h>
0011 #include <linux/i2c.h>
0012 #include <linux/module.h>
0013 #include <linux/pm_runtime.h>
0014 #include <linux/regmap.h>
0015 #include <linux/regulator/consumer.h>
0016 #include <linux/slab.h>
0017 #include <linux/of.h>
0018 
0019 #include <linux/mfd/arizona/core.h>
0020 
0021 #include "arizona.h"
0022 
0023 static int arizona_i2c_probe(struct i2c_client *i2c,
0024                  const struct i2c_device_id *id)
0025 {
0026     const void *match_data;
0027     struct arizona *arizona;
0028     const struct regmap_config *regmap_config = NULL;
0029     unsigned long type = 0;
0030     int ret;
0031 
0032     match_data = device_get_match_data(&i2c->dev);
0033     if (match_data)
0034         type = (unsigned long)match_data;
0035     else if (id)
0036         type = id->driver_data;
0037 
0038     switch (type) {
0039     case WM5102:
0040         if (IS_ENABLED(CONFIG_MFD_WM5102))
0041             regmap_config = &wm5102_i2c_regmap;
0042         break;
0043     case WM5110:
0044     case WM8280:
0045         if (IS_ENABLED(CONFIG_MFD_WM5110))
0046             regmap_config = &wm5110_i2c_regmap;
0047         break;
0048     case WM8997:
0049         if (IS_ENABLED(CONFIG_MFD_WM8997))
0050             regmap_config = &wm8997_i2c_regmap;
0051         break;
0052     case WM8998:
0053     case WM1814:
0054         if (IS_ENABLED(CONFIG_MFD_WM8998))
0055             regmap_config = &wm8998_i2c_regmap;
0056         break;
0057     default:
0058         dev_err(&i2c->dev, "Unknown device type %ld\n", type);
0059         return -EINVAL;
0060     }
0061 
0062     if (!regmap_config) {
0063         dev_err(&i2c->dev,
0064             "No kernel support for device type %ld\n", type);
0065         return -EINVAL;
0066     }
0067 
0068     arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL);
0069     if (arizona == NULL)
0070         return -ENOMEM;
0071 
0072     arizona->regmap = devm_regmap_init_i2c(i2c, regmap_config);
0073     if (IS_ERR(arizona->regmap)) {
0074         ret = PTR_ERR(arizona->regmap);
0075         dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
0076             ret);
0077         return ret;
0078     }
0079 
0080     arizona->type = type;
0081     arizona->dev = &i2c->dev;
0082     arizona->irq = i2c->irq;
0083 
0084     return arizona_dev_init(arizona);
0085 }
0086 
0087 static int arizona_i2c_remove(struct i2c_client *i2c)
0088 {
0089     struct arizona *arizona = dev_get_drvdata(&i2c->dev);
0090 
0091     arizona_dev_exit(arizona);
0092 
0093     return 0;
0094 }
0095 
0096 static const struct i2c_device_id arizona_i2c_id[] = {
0097     { "wm5102", WM5102 },
0098     { "wm5110", WM5110 },
0099     { "wm8280", WM8280 },
0100     { "wm8997", WM8997 },
0101     { "wm8998", WM8998 },
0102     { "wm1814", WM1814 },
0103     { }
0104 };
0105 MODULE_DEVICE_TABLE(i2c, arizona_i2c_id);
0106 
0107 #ifdef CONFIG_OF
0108 static const struct of_device_id arizona_i2c_of_match[] = {
0109     { .compatible = "wlf,wm5102", .data = (void *)WM5102 },
0110     { .compatible = "wlf,wm5110", .data = (void *)WM5110 },
0111     { .compatible = "wlf,wm8280", .data = (void *)WM8280 },
0112     { .compatible = "wlf,wm8997", .data = (void *)WM8997 },
0113     { .compatible = "wlf,wm8998", .data = (void *)WM8998 },
0114     { .compatible = "wlf,wm1814", .data = (void *)WM1814 },
0115     {},
0116 };
0117 #endif
0118 
0119 static struct i2c_driver arizona_i2c_driver = {
0120     .driver = {
0121         .name   = "arizona",
0122         .pm = &arizona_pm_ops,
0123         .of_match_table = of_match_ptr(arizona_i2c_of_match),
0124     },
0125     .probe      = arizona_i2c_probe,
0126     .remove     = arizona_i2c_remove,
0127     .id_table   = arizona_i2c_id,
0128 };
0129 
0130 module_i2c_driver(arizona_i2c_driver);
0131 
0132 MODULE_SOFTDEP("pre: arizona_ldo1");
0133 MODULE_DESCRIPTION("Arizona I2C bus interface");
0134 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
0135 MODULE_LICENSE("GPL");