Linux Audio

Check our new training course

Loading...
v3.1
  1/*
  2 * tps6507x.c  --  TPS6507x chip family multi-function driver
  3 *
  4 *  Copyright (c) 2010 RidgeRun (todd.fischer@ridgerun.com)
  5 *
  6 * Author: Todd Fischer
  7 *         todd.fischer@ridgerun.com
  8 *
  9 * Credits:
 10 *
 11 *    Using code from wm831x-*.c, wm8400-core, Wolfson Microelectronics PLC.
 12 *
 13 * For licencing details see kernel-base/COPYING
 14 *
 15 */
 16
 17#include <linux/module.h>
 18#include <linux/moduleparam.h>
 19#include <linux/init.h>
 20#include <linux/slab.h>
 21#include <linux/i2c.h>
 
 
 22#include <linux/mfd/core.h>
 23#include <linux/mfd/tps6507x.h>
 24
 25static struct mfd_cell tps6507x_devs[] = {
 26	{
 27		.name = "tps6507x-pmic",
 28	},
 29	{
 30		.name = "tps6507x-ts",
 31	},
 32};
 33
 34
 35static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
 36				  int bytes, void *dest)
 37{
 38	struct i2c_client *i2c = tps6507x->i2c_client;
 39	struct i2c_msg xfer[2];
 40	int ret;
 41
 42	/* Write register */
 43	xfer[0].addr = i2c->addr;
 44	xfer[0].flags = 0;
 45	xfer[0].len = 1;
 46	xfer[0].buf = &reg;
 47
 48	/* Read data */
 49	xfer[1].addr = i2c->addr;
 50	xfer[1].flags = I2C_M_RD;
 51	xfer[1].len = bytes;
 52	xfer[1].buf = dest;
 53
 54	ret = i2c_transfer(i2c->adapter, xfer, 2);
 55	if (ret == 2)
 56		ret = 0;
 57	else if (ret >= 0)
 58		ret = -EIO;
 59
 60	return ret;
 61}
 62
 63static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
 64				   int bytes, void *src)
 65{
 66	struct i2c_client *i2c = tps6507x->i2c_client;
 67	/* we add 1 byte for device register */
 68	u8 msg[TPS6507X_MAX_REGISTER + 1];
 69	int ret;
 70
 71	if (bytes > TPS6507X_MAX_REGISTER)
 72		return -EINVAL;
 73
 74	msg[0] = reg;
 75	memcpy(&msg[1], src, bytes);
 76
 77	ret = i2c_master_send(i2c, msg, bytes + 1);
 78	if (ret < 0)
 79		return ret;
 80	if (ret != bytes + 1)
 81		return -EIO;
 82	return 0;
 83}
 84
 85static int tps6507x_i2c_probe(struct i2c_client *i2c,
 86			    const struct i2c_device_id *id)
 87{
 88	struct tps6507x_dev *tps6507x;
 89	int ret = 0;
 90
 91	tps6507x = kzalloc(sizeof(struct tps6507x_dev), GFP_KERNEL);
 
 92	if (tps6507x == NULL)
 93		return -ENOMEM;
 94
 95	i2c_set_clientdata(i2c, tps6507x);
 96	tps6507x->dev = &i2c->dev;
 97	tps6507x->i2c_client = i2c;
 98	tps6507x->read_dev = tps6507x_i2c_read_device;
 99	tps6507x->write_dev = tps6507x_i2c_write_device;
100
101	ret = mfd_add_devices(tps6507x->dev, -1,
102			      tps6507x_devs, ARRAY_SIZE(tps6507x_devs),
103			      NULL, 0);
104
105	if (ret < 0)
106		goto err;
107
108	return ret;
109
110err:
111	mfd_remove_devices(tps6507x->dev);
112	kfree(tps6507x);
113	return ret;
114}
115
116static int tps6507x_i2c_remove(struct i2c_client *i2c)
117{
118	struct tps6507x_dev *tps6507x = i2c_get_clientdata(i2c);
119
120	mfd_remove_devices(tps6507x->dev);
121	kfree(tps6507x);
122
123	return 0;
124}
125
126static const struct i2c_device_id tps6507x_i2c_id[] = {
127       { "tps6507x", 0 },
128       { }
129};
130MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
131
 
 
 
 
 
 
 
132
133static struct i2c_driver tps6507x_i2c_driver = {
134	.driver = {
135		   .name = "tps6507x",
136		   .owner = THIS_MODULE,
137	},
138	.probe = tps6507x_i2c_probe,
139	.remove = tps6507x_i2c_remove,
140	.id_table = tps6507x_i2c_id,
141};
142
143static int __init tps6507x_i2c_init(void)
144{
145	return i2c_add_driver(&tps6507x_i2c_driver);
146}
147/* init early so consumer devices can complete system boot */
148subsys_initcall(tps6507x_i2c_init);
149
150static void __exit tps6507x_i2c_exit(void)
151{
152	i2c_del_driver(&tps6507x_i2c_driver);
153}
154module_exit(tps6507x_i2c_exit);
155
156MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
157MODULE_LICENSE("GPL");
v5.14.15
  1/*
  2 * tps6507x.c  --  TPS6507x chip family multi-function driver
  3 *
  4 *  Copyright (c) 2010 RidgeRun (todd.fischer@ridgerun.com)
  5 *
  6 * Author: Todd Fischer
  7 *         todd.fischer@ridgerun.com
  8 *
  9 * Credits:
 10 *
 11 *    Using code from wm831x-*.c, wm8400-core, Wolfson Microelectronics PLC.
 12 *
 13 * For licencing details see kernel-base/COPYING
 14 *
 15 */
 16
 17#include <linux/module.h>
 18#include <linux/moduleparam.h>
 19#include <linux/init.h>
 20#include <linux/slab.h>
 21#include <linux/i2c.h>
 22#include <linux/of.h>
 23#include <linux/of_device.h>
 24#include <linux/mfd/core.h>
 25#include <linux/mfd/tps6507x.h>
 26
 27static const struct mfd_cell tps6507x_devs[] = {
 28	{
 29		.name = "tps6507x-pmic",
 30	},
 31	{
 32		.name = "tps6507x-ts",
 33	},
 34};
 35
 36
 37static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
 38				  int bytes, void *dest)
 39{
 40	struct i2c_client *i2c = tps6507x->i2c_client;
 41	struct i2c_msg xfer[2];
 42	int ret;
 43
 44	/* Write register */
 45	xfer[0].addr = i2c->addr;
 46	xfer[0].flags = 0;
 47	xfer[0].len = 1;
 48	xfer[0].buf = &reg;
 49
 50	/* Read data */
 51	xfer[1].addr = i2c->addr;
 52	xfer[1].flags = I2C_M_RD;
 53	xfer[1].len = bytes;
 54	xfer[1].buf = dest;
 55
 56	ret = i2c_transfer(i2c->adapter, xfer, 2);
 57	if (ret == 2)
 58		ret = 0;
 59	else if (ret >= 0)
 60		ret = -EIO;
 61
 62	return ret;
 63}
 64
 65static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
 66				   int bytes, void *src)
 67{
 68	struct i2c_client *i2c = tps6507x->i2c_client;
 69	/* we add 1 byte for device register */
 70	u8 msg[TPS6507X_MAX_REGISTER + 1];
 71	int ret;
 72
 73	if (bytes > TPS6507X_MAX_REGISTER)
 74		return -EINVAL;
 75
 76	msg[0] = reg;
 77	memcpy(&msg[1], src, bytes);
 78
 79	ret = i2c_master_send(i2c, msg, bytes + 1);
 80	if (ret < 0)
 81		return ret;
 82	if (ret != bytes + 1)
 83		return -EIO;
 84	return 0;
 85}
 86
 87static int tps6507x_i2c_probe(struct i2c_client *i2c,
 88			    const struct i2c_device_id *id)
 89{
 90	struct tps6507x_dev *tps6507x;
 
 91
 92	tps6507x = devm_kzalloc(&i2c->dev, sizeof(struct tps6507x_dev),
 93				GFP_KERNEL);
 94	if (tps6507x == NULL)
 95		return -ENOMEM;
 96
 97	i2c_set_clientdata(i2c, tps6507x);
 98	tps6507x->dev = &i2c->dev;
 99	tps6507x->i2c_client = i2c;
100	tps6507x->read_dev = tps6507x_i2c_read_device;
101	tps6507x->write_dev = tps6507x_i2c_write_device;
102
103	return devm_mfd_add_devices(tps6507x->dev, -1, tps6507x_devs,
104				    ARRAY_SIZE(tps6507x_devs), NULL, 0, NULL);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105}
106
107static const struct i2c_device_id tps6507x_i2c_id[] = {
108	{ "tps6507x", 0 },
109	{ }
110};
111MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
112
113#ifdef CONFIG_OF
114static const struct of_device_id tps6507x_of_match[] = {
115	{.compatible = "ti,tps6507x", },
116	{},
117};
118MODULE_DEVICE_TABLE(of, tps6507x_of_match);
119#endif
120
121static struct i2c_driver tps6507x_i2c_driver = {
122	.driver = {
123		   .name = "tps6507x",
124		   .of_match_table = of_match_ptr(tps6507x_of_match),
125	},
126	.probe = tps6507x_i2c_probe,
 
127	.id_table = tps6507x_i2c_id,
128};
129
130static int __init tps6507x_i2c_init(void)
131{
132	return i2c_add_driver(&tps6507x_i2c_driver);
133}
134/* init early so consumer devices can complete system boot */
135subsys_initcall(tps6507x_i2c_init);
136
137static void __exit tps6507x_i2c_exit(void)
138{
139	i2c_del_driver(&tps6507x_i2c_driver);
140}
141module_exit(tps6507x_i2c_exit);
142
143MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
144MODULE_LICENSE("GPL");