Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * wm831x-i2c.c  --  I2C access for Wolfson WM831x PMICs
  4 *
  5 * Copyright 2009,2010 Wolfson Microelectronics PLC.
  6 *
  7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
 
 
 
 
 
 
  8 */
  9
 10#include <linux/kernel.h>
 11#include <linux/init.h>
 12#include <linux/i2c.h>
 13#include <linux/delay.h>
 14#include <linux/mfd/core.h>
 15#include <linux/slab.h>
 16#include <linux/err.h>
 17#include <linux/of.h>
 18#include <linux/regmap.h>
 19
 20#include <linux/mfd/wm831x/core.h>
 21#include <linux/mfd/wm831x/pdata.h>
 22
 23static int wm831x_i2c_probe(struct i2c_client *i2c)
 
 24{
 25	struct wm831x_pdata *pdata = dev_get_platdata(&i2c->dev);
 26	struct wm831x *wm831x;
 27	enum wm831x_parent type;
 28	int ret;
 29
 30	type = (uintptr_t)i2c_get_match_data(i2c);
 31	if (!type) {
 32		dev_err(&i2c->dev, "Failed to match device\n");
 33		return -ENODEV;
 34	}
 35
 36	wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL);
 37	if (wm831x == NULL)
 38		return -ENOMEM;
 39
 40	i2c_set_clientdata(i2c, wm831x);
 41	wm831x->dev = &i2c->dev;
 42	wm831x->type = type;
 43
 44	wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config);
 45	if (IS_ERR(wm831x->regmap)) {
 46		ret = PTR_ERR(wm831x->regmap);
 47		dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
 48			ret);
 49		return ret;
 50	}
 51
 52	if (pdata)
 53		memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
 
 
 
 
 
 
 54
 55	return wm831x_device_init(wm831x, i2c->irq);
 56}
 57
 58static int wm831x_i2c_suspend(struct device *dev)
 59{
 60	struct wm831x *wm831x = dev_get_drvdata(dev);
 61
 62	return wm831x_device_suspend(wm831x);
 63}
 64
 65static int wm831x_i2c_poweroff(struct device *dev)
 66{
 67	struct wm831x *wm831x = dev_get_drvdata(dev);
 68
 69	wm831x_device_shutdown(wm831x);
 70
 71	return 0;
 72}
 73
 74static const struct i2c_device_id wm831x_i2c_id[] = {
 75	{ "wm8310", WM8310 },
 76	{ "wm8311", WM8311 },
 77	{ "wm8312", WM8312 },
 78	{ "wm8320", WM8320 },
 79	{ "wm8321", WM8321 },
 80	{ "wm8325", WM8325 },
 81	{ "wm8326", WM8326 },
 82	{ }
 83};
 
 84
 85static const struct dev_pm_ops wm831x_pm_ops = {
 86	.suspend = wm831x_i2c_suspend,
 87	.poweroff = wm831x_i2c_poweroff,
 88};
 89
 90static struct i2c_driver wm831x_i2c_driver = {
 91	.driver = {
 92		.name = "wm831x",
 93		.pm = &wm831x_pm_ops,
 94		.of_match_table = of_match_ptr(wm831x_of_match),
 95		.suppress_bind_attrs = true,
 96	},
 97	.probe = wm831x_i2c_probe,
 
 98	.id_table = wm831x_i2c_id,
 99};
100
101static int __init wm831x_i2c_init(void)
102{
103	int ret;
104
105	ret = i2c_add_driver(&wm831x_i2c_driver);
106	if (ret != 0)
107		pr_err("Failed to register wm831x I2C driver: %d\n", ret);
108
109	return ret;
110}
111subsys_initcall(wm831x_i2c_init);
v4.10.11
 
  1/*
  2 * wm831x-i2c.c  --  I2C access for Wolfson WM831x PMICs
  3 *
  4 * Copyright 2009,2010 Wolfson Microelectronics PLC.
  5 *
  6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7 *
  8 *  This program is free software; you can redistribute  it and/or modify it
  9 *  under  the terms of  the GNU General  Public License as published by the
 10 *  Free Software Foundation;  either version 2 of the  License, or (at your
 11 *  option) any later version.
 12 *
 13 */
 14
 15#include <linux/kernel.h>
 16#include <linux/module.h>
 17#include <linux/i2c.h>
 18#include <linux/delay.h>
 19#include <linux/mfd/core.h>
 20#include <linux/slab.h>
 21#include <linux/err.h>
 
 22#include <linux/regmap.h>
 23
 24#include <linux/mfd/wm831x/core.h>
 25#include <linux/mfd/wm831x/pdata.h>
 26
 27static int wm831x_i2c_probe(struct i2c_client *i2c,
 28			    const struct i2c_device_id *id)
 29{
 
 30	struct wm831x *wm831x;
 
 31	int ret;
 32
 
 
 
 
 
 
 33	wm831x = devm_kzalloc(&i2c->dev, sizeof(struct wm831x), GFP_KERNEL);
 34	if (wm831x == NULL)
 35		return -ENOMEM;
 36
 37	i2c_set_clientdata(i2c, wm831x);
 38	wm831x->dev = &i2c->dev;
 
 39
 40	wm831x->regmap = devm_regmap_init_i2c(i2c, &wm831x_regmap_config);
 41	if (IS_ERR(wm831x->regmap)) {
 42		ret = PTR_ERR(wm831x->regmap);
 43		dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
 44			ret);
 45		return ret;
 46	}
 47
 48	return wm831x_device_init(wm831x, id->driver_data, i2c->irq);
 49}
 50
 51static int wm831x_i2c_remove(struct i2c_client *i2c)
 52{
 53	struct wm831x *wm831x = i2c_get_clientdata(i2c);
 54
 55	wm831x_device_exit(wm831x);
 56
 57	return 0;
 58}
 59
 60static int wm831x_i2c_suspend(struct device *dev)
 61{
 62	struct wm831x *wm831x = dev_get_drvdata(dev);
 63
 64	return wm831x_device_suspend(wm831x);
 65}
 66
 67static int wm831x_i2c_poweroff(struct device *dev)
 68{
 69	struct wm831x *wm831x = dev_get_drvdata(dev);
 70
 71	wm831x_device_shutdown(wm831x);
 72
 73	return 0;
 74}
 75
 76static const struct i2c_device_id wm831x_i2c_id[] = {
 77	{ "wm8310", WM8310 },
 78	{ "wm8311", WM8311 },
 79	{ "wm8312", WM8312 },
 80	{ "wm8320", WM8320 },
 81	{ "wm8321", WM8321 },
 82	{ "wm8325", WM8325 },
 83	{ "wm8326", WM8326 },
 84	{ }
 85};
 86MODULE_DEVICE_TABLE(i2c, wm831x_i2c_id);
 87
 88static const struct dev_pm_ops wm831x_pm_ops = {
 89	.suspend = wm831x_i2c_suspend,
 90	.poweroff = wm831x_i2c_poweroff,
 91};
 92
 93static struct i2c_driver wm831x_i2c_driver = {
 94	.driver = {
 95		.name = "wm831x",
 96		.pm = &wm831x_pm_ops,
 
 
 97	},
 98	.probe = wm831x_i2c_probe,
 99	.remove = wm831x_i2c_remove,
100	.id_table = wm831x_i2c_id,
101};
102
103static int __init wm831x_i2c_init(void)
104{
105	int ret;
106
107	ret = i2c_add_driver(&wm831x_i2c_driver);
108	if (ret != 0)
109		pr_err("Failed to register wm831x I2C driver: %d\n", ret);
110
111	return ret;
112}
113subsys_initcall(wm831x_i2c_init);
114
115static void __exit wm831x_i2c_exit(void)
116{
117	i2c_del_driver(&wm831x_i2c_driver);
118}
119module_exit(wm831x_i2c_exit);