Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0-only
 2/*
 3 * sky81452.c	SKY81452 MFD driver
 4 *
 5 * Copyright 2014 Skyworks Solutions Inc.
 6 * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
 
 
 
 
 
 
 
 
 
 
 
 
 7 */
 8
 9#include <linux/kernel.h>
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/err.h>
13#include <linux/slab.h>
14#include <linux/i2c.h>
15#include <linux/regmap.h>
16#include <linux/mfd/core.h>
17#include <linux/mfd/sky81452.h>
18
19static const struct regmap_config sky81452_config = {
20	.reg_bits = 8,
21	.val_bits = 8,
22};
23
24static int sky81452_probe(struct i2c_client *client)
 
25{
26	struct device *dev = &client->dev;
27	const struct sky81452_platform_data *pdata = dev_get_platdata(dev);
28	struct mfd_cell cells[2];
29	struct regmap *regmap;
30	int ret;
31
32	if (!pdata) {
33		pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
34		if (!pdata)
35			return -ENOMEM;
36	}
37
38	regmap = devm_regmap_init_i2c(client, &sky81452_config);
39	if (IS_ERR(regmap)) {
40		dev_err(dev, "failed to initialize.err=%ld\n", PTR_ERR(regmap));
41		return PTR_ERR(regmap);
42	}
43
44	i2c_set_clientdata(client, regmap);
45
46	memset(cells, 0, sizeof(cells));
47	cells[0].name = "sky81452-backlight";
48	cells[0].of_compatible = "skyworks,sky81452-backlight";
 
 
49	cells[1].name = "sky81452-regulator";
50	cells[1].platform_data = pdata->regulator_init_data;
51	cells[1].pdata_size = sizeof(*pdata->regulator_init_data);
52
53	ret = devm_mfd_add_devices(dev, -1, cells, ARRAY_SIZE(cells),
54				   NULL, 0, NULL);
55	if (ret)
56		dev_err(dev, "failed to add child devices. err=%d\n", ret);
57
58	return ret;
59}
60
61static const struct i2c_device_id sky81452_ids[] = {
62	{ "sky81452" },
63	{ }
64};
65MODULE_DEVICE_TABLE(i2c, sky81452_ids);
66
67#ifdef CONFIG_OF
68static const struct of_device_id sky81452_of_match[] = {
69	{ .compatible = "skyworks,sky81452", },
70	{ }
71};
72MODULE_DEVICE_TABLE(of, sky81452_of_match);
73#endif
74
75static struct i2c_driver sky81452_driver = {
76	.driver = {
77		.name = "sky81452",
78		.of_match_table = of_match_ptr(sky81452_of_match),
79	},
80	.probe = sky81452_probe,
81	.id_table = sky81452_ids,
82};
83
84module_i2c_driver(sky81452_driver);
85
86MODULE_DESCRIPTION("Skyworks SKY81452 MFD driver");
87MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
88MODULE_LICENSE("GPL v2");
v4.17
 
  1/*
  2 * sky81452.c	SKY81452 MFD driver
  3 *
  4 * Copyright 2014 Skyworks Solutions Inc.
  5 * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
  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 version 2
  9 * as published by the Free Software Foundation.
 10 *
 11 * This program is distributed in the hope that it will be useful, but
 12 * WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14 * General Public License for more details.
 15 *
 16 * You should have received a copy of the GNU General Public License along
 17 * with this program; if not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#include <linux/kernel.h>
 21#include <linux/module.h>
 22#include <linux/init.h>
 23#include <linux/err.h>
 24#include <linux/slab.h>
 25#include <linux/i2c.h>
 26#include <linux/regmap.h>
 27#include <linux/mfd/core.h>
 28#include <linux/mfd/sky81452.h>
 29
 30static const struct regmap_config sky81452_config = {
 31	.reg_bits = 8,
 32	.val_bits = 8,
 33};
 34
 35static int sky81452_probe(struct i2c_client *client,
 36				const struct i2c_device_id *id)
 37{
 38	struct device *dev = &client->dev;
 39	const struct sky81452_platform_data *pdata = dev_get_platdata(dev);
 40	struct mfd_cell cells[2];
 41	struct regmap *regmap;
 42	int ret;
 43
 44	if (!pdata) {
 45		pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
 46		if (!pdata)
 47			return -ENOMEM;
 48	}
 49
 50	regmap = devm_regmap_init_i2c(client, &sky81452_config);
 51	if (IS_ERR(regmap)) {
 52		dev_err(dev, "failed to initialize.err=%ld\n", PTR_ERR(regmap));
 53		return PTR_ERR(regmap);
 54	}
 55
 56	i2c_set_clientdata(client, regmap);
 57
 58	memset(cells, 0, sizeof(cells));
 59	cells[0].name = "sky81452-backlight";
 60	cells[0].of_compatible = "skyworks,sky81452-backlight";
 61	cells[0].platform_data = pdata->bl_pdata;
 62	cells[0].pdata_size = sizeof(*pdata->bl_pdata);
 63	cells[1].name = "sky81452-regulator";
 64	cells[1].platform_data = pdata->regulator_init_data;
 65	cells[1].pdata_size = sizeof(*pdata->regulator_init_data);
 66
 67	ret = devm_mfd_add_devices(dev, -1, cells, ARRAY_SIZE(cells),
 68				   NULL, 0, NULL);
 69	if (ret)
 70		dev_err(dev, "failed to add child devices. err=%d\n", ret);
 71
 72	return ret;
 73}
 74
 75static const struct i2c_device_id sky81452_ids[] = {
 76	{ "sky81452" },
 77	{ }
 78};
 79MODULE_DEVICE_TABLE(i2c, sky81452_ids);
 80
 81#ifdef CONFIG_OF
 82static const struct of_device_id sky81452_of_match[] = {
 83	{ .compatible = "skyworks,sky81452", },
 84	{ }
 85};
 86MODULE_DEVICE_TABLE(of, sky81452_of_match);
 87#endif
 88
 89static struct i2c_driver sky81452_driver = {
 90	.driver = {
 91		.name = "sky81452",
 92		.of_match_table = of_match_ptr(sky81452_of_match),
 93	},
 94	.probe = sky81452_probe,
 95	.id_table = sky81452_ids,
 96};
 97
 98module_i2c_driver(sky81452_driver);
 99
100MODULE_DESCRIPTION("Skyworks SKY81452 MFD driver");
101MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
102MODULE_LICENSE("GPL v2");