Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * sky81452.c   SKY81452 MFD driver
0004  *
0005  * Copyright 2014 Skyworks Solutions Inc.
0006  * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
0007  */
0008 
0009 #include <linux/kernel.h>
0010 #include <linux/module.h>
0011 #include <linux/init.h>
0012 #include <linux/err.h>
0013 #include <linux/slab.h>
0014 #include <linux/i2c.h>
0015 #include <linux/regmap.h>
0016 #include <linux/mfd/core.h>
0017 #include <linux/mfd/sky81452.h>
0018 
0019 static const struct regmap_config sky81452_config = {
0020     .reg_bits = 8,
0021     .val_bits = 8,
0022 };
0023 
0024 static int sky81452_probe(struct i2c_client *client,
0025                 const struct i2c_device_id *id)
0026 {
0027     struct device *dev = &client->dev;
0028     const struct sky81452_platform_data *pdata = dev_get_platdata(dev);
0029     struct mfd_cell cells[2];
0030     struct regmap *regmap;
0031     int ret;
0032 
0033     if (!pdata) {
0034         pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
0035         if (!pdata)
0036             return -ENOMEM;
0037     }
0038 
0039     regmap = devm_regmap_init_i2c(client, &sky81452_config);
0040     if (IS_ERR(regmap)) {
0041         dev_err(dev, "failed to initialize.err=%ld\n", PTR_ERR(regmap));
0042         return PTR_ERR(regmap);
0043     }
0044 
0045     i2c_set_clientdata(client, regmap);
0046 
0047     memset(cells, 0, sizeof(cells));
0048     cells[0].name = "sky81452-backlight";
0049     cells[0].of_compatible = "skyworks,sky81452-backlight";
0050     cells[1].name = "sky81452-regulator";
0051     cells[1].platform_data = pdata->regulator_init_data;
0052     cells[1].pdata_size = sizeof(*pdata->regulator_init_data);
0053 
0054     ret = devm_mfd_add_devices(dev, -1, cells, ARRAY_SIZE(cells),
0055                    NULL, 0, NULL);
0056     if (ret)
0057         dev_err(dev, "failed to add child devices. err=%d\n", ret);
0058 
0059     return ret;
0060 }
0061 
0062 static const struct i2c_device_id sky81452_ids[] = {
0063     { "sky81452" },
0064     { }
0065 };
0066 MODULE_DEVICE_TABLE(i2c, sky81452_ids);
0067 
0068 #ifdef CONFIG_OF
0069 static const struct of_device_id sky81452_of_match[] = {
0070     { .compatible = "skyworks,sky81452", },
0071     { }
0072 };
0073 MODULE_DEVICE_TABLE(of, sky81452_of_match);
0074 #endif
0075 
0076 static struct i2c_driver sky81452_driver = {
0077     .driver = {
0078         .name = "sky81452",
0079         .of_match_table = of_match_ptr(sky81452_of_match),
0080     },
0081     .probe = sky81452_probe,
0082     .id_table = sky81452_ids,
0083 };
0084 
0085 module_i2c_driver(sky81452_driver);
0086 
0087 MODULE_DESCRIPTION("Skyworks SKY81452 MFD driver");
0088 MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
0089 MODULE_LICENSE("GPL v2");