Linux Audio

Check our new training course

Loading...
v6.8
  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/mfd/core.h>
 24#include <linux/mfd/tps6507x.h>
 25
 26static const struct mfd_cell tps6507x_devs[] = {
 27	{
 28		.name = "tps6507x-pmic",
 29	},
 30	{
 31		.name = "tps6507x-ts",
 32	},
 33};
 34
 35
 36static int tps6507x_i2c_read_device(struct tps6507x_dev *tps6507x, char reg,
 37				  int bytes, void *dest)
 38{
 39	struct i2c_client *i2c = tps6507x->i2c_client;
 40	struct i2c_msg xfer[2];
 41	int ret;
 42
 43	/* Write register */
 44	xfer[0].addr = i2c->addr;
 45	xfer[0].flags = 0;
 46	xfer[0].len = 1;
 47	xfer[0].buf = &reg;
 48
 49	/* Read data */
 50	xfer[1].addr = i2c->addr;
 51	xfer[1].flags = I2C_M_RD;
 52	xfer[1].len = bytes;
 53	xfer[1].buf = dest;
 54
 55	ret = i2c_transfer(i2c->adapter, xfer, 2);
 56	if (ret == 2)
 57		ret = 0;
 58	else if (ret >= 0)
 59		ret = -EIO;
 60
 61	return ret;
 62}
 63
 64static int tps6507x_i2c_write_device(struct tps6507x_dev *tps6507x, char reg,
 65				   int bytes, void *src)
 66{
 67	struct i2c_client *i2c = tps6507x->i2c_client;
 68	/* we add 1 byte for device register */
 69	u8 msg[TPS6507X_MAX_REGISTER + 1];
 70	int ret;
 71
 72	if (bytes > TPS6507X_MAX_REGISTER)
 73		return -EINVAL;
 74
 75	msg[0] = reg;
 76	memcpy(&msg[1], src, bytes);
 77
 78	ret = i2c_master_send(i2c, msg, bytes + 1);
 79	if (ret < 0)
 80		return ret;
 81	if (ret != bytes + 1)
 82		return -EIO;
 83	return 0;
 84}
 85
 86static int tps6507x_i2c_probe(struct i2c_client *i2c)
 87{
 88	struct tps6507x_dev *tps6507x;
 89
 90	tps6507x = devm_kzalloc(&i2c->dev, sizeof(struct tps6507x_dev),
 91				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	return devm_mfd_add_devices(tps6507x->dev, -1, tps6507x_devs,
102				    ARRAY_SIZE(tps6507x_devs), NULL, 0, NULL);
103}
104
105static const struct i2c_device_id tps6507x_i2c_id[] = {
106	{ "tps6507x", 0 },
107	{ }
108};
109MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
110
111#ifdef CONFIG_OF
112static const struct of_device_id tps6507x_of_match[] = {
113	{.compatible = "ti,tps6507x", },
114	{},
115};
116MODULE_DEVICE_TABLE(of, tps6507x_of_match);
117#endif
118
119static struct i2c_driver tps6507x_i2c_driver = {
120	.driver = {
121		   .name = "tps6507x",
122		   .of_match_table = of_match_ptr(tps6507x_of_match),
123	},
124	.probe = tps6507x_i2c_probe,
125	.id_table = tps6507x_i2c_id,
126};
127
128static int __init tps6507x_i2c_init(void)
129{
130	return i2c_add_driver(&tps6507x_i2c_driver);
131}
132/* init early so consumer devices can complete system boot */
133subsys_initcall(tps6507x_i2c_init);
134
135static void __exit tps6507x_i2c_exit(void)
136{
137	i2c_del_driver(&tps6507x_i2c_driver);
138}
139module_exit(tps6507x_i2c_exit);
140
141MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
142MODULE_LICENSE("GPL");
v6.2
  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{
 89	struct tps6507x_dev *tps6507x;
 90
 91	tps6507x = devm_kzalloc(&i2c->dev, sizeof(struct tps6507x_dev),
 92				GFP_KERNEL);
 93	if (tps6507x == NULL)
 94		return -ENOMEM;
 95
 96	i2c_set_clientdata(i2c, tps6507x);
 97	tps6507x->dev = &i2c->dev;
 98	tps6507x->i2c_client = i2c;
 99	tps6507x->read_dev = tps6507x_i2c_read_device;
100	tps6507x->write_dev = tps6507x_i2c_write_device;
101
102	return devm_mfd_add_devices(tps6507x->dev, -1, tps6507x_devs,
103				    ARRAY_SIZE(tps6507x_devs), NULL, 0, NULL);
104}
105
106static const struct i2c_device_id tps6507x_i2c_id[] = {
107	{ "tps6507x", 0 },
108	{ }
109};
110MODULE_DEVICE_TABLE(i2c, tps6507x_i2c_id);
111
112#ifdef CONFIG_OF
113static const struct of_device_id tps6507x_of_match[] = {
114	{.compatible = "ti,tps6507x", },
115	{},
116};
117MODULE_DEVICE_TABLE(of, tps6507x_of_match);
118#endif
119
120static struct i2c_driver tps6507x_i2c_driver = {
121	.driver = {
122		   .name = "tps6507x",
123		   .of_match_table = of_match_ptr(tps6507x_of_match),
124	},
125	.probe_new = tps6507x_i2c_probe,
126	.id_table = tps6507x_i2c_id,
127};
128
129static int __init tps6507x_i2c_init(void)
130{
131	return i2c_add_driver(&tps6507x_i2c_driver);
132}
133/* init early so consumer devices can complete system boot */
134subsys_initcall(tps6507x_i2c_init);
135
136static void __exit tps6507x_i2c_exit(void)
137{
138	i2c_del_driver(&tps6507x_i2c_driver);
139}
140module_exit(tps6507x_i2c_exit);
141
142MODULE_DESCRIPTION("TPS6507x chip family multi-function driver");
143MODULE_LICENSE("GPL");