Linux Audio

Check our new training course

Loading...
v3.1
  1/*
  2 * tps65912-core.c  --  TI TPS65912x
  3 *
  4 * Copyright 2011 Texas Instruments Inc.
 
  5 *
  6 * Author: Margarita Olaya Cabrera <magi@slimlogic.co.uk>
 
 
  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 *  This driver is based on wm8350 implementation.
 
 14 */
 15
 16#include <linux/module.h>
 17#include <linux/moduleparam.h>
 18#include <linux/init.h>
 19#include <linux/slab.h>
 20#include <linux/gpio.h>
 21#include <linux/mfd/core.h>
 
 
 22#include <linux/mfd/tps65912.h>
 23
 24static struct mfd_cell tps65912s[] = {
 25	{
 26		.name = "tps65912-pmic",
 27	},
 28};
 29
 30int tps65912_set_bits(struct tps65912 *tps65912, u8 reg, u8 mask)
 31{
 32	u8 data;
 33	int err;
 34
 35	mutex_lock(&tps65912->io_mutex);
 36
 37	err = tps65912->read(tps65912, reg, 1, &data);
 38	if (err) {
 39		dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
 40		goto out;
 41	}
 42
 43	data |= mask;
 44	err = tps65912->write(tps65912, reg, 1, &data);
 45	if (err)
 46		dev_err(tps65912->dev, "Write to reg 0x%x failed\n", reg);
 47
 48out:
 49	mutex_unlock(&tps65912->io_mutex);
 50	return err;
 51}
 52EXPORT_SYMBOL_GPL(tps65912_set_bits);
 53
 54int tps65912_clear_bits(struct tps65912 *tps65912, u8 reg, u8 mask)
 55{
 56	u8 data;
 57	int err;
 58
 59	mutex_lock(&tps65912->io_mutex);
 60	err = tps65912->read(tps65912, reg, 1, &data);
 61	if (err) {
 62		dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
 63		goto out;
 64	}
 65
 66	data &= ~mask;
 67	err = tps65912->write(tps65912, reg, 1, &data);
 68	if (err)
 69		dev_err(tps65912->dev, "Write to reg 0x%x failed\n", reg);
 70
 71out:
 72	mutex_unlock(&tps65912->io_mutex);
 73	return err;
 74}
 75EXPORT_SYMBOL_GPL(tps65912_clear_bits);
 76
 77static inline int tps65912_read(struct tps65912 *tps65912, u8 reg)
 78{
 79	u8 val;
 80	int err;
 81
 82	err = tps65912->read(tps65912, reg, 1, &val);
 83	if (err < 0)
 84		return err;
 85
 86	return val;
 87}
 88
 89static inline int tps65912_write(struct tps65912 *tps65912, u8 reg, u8 val)
 90{
 91	return tps65912->write(tps65912, reg, 1, &val);
 92}
 93
 94int tps65912_reg_read(struct tps65912 *tps65912, u8 reg)
 95{
 96	int data;
 
 
 
 
 
 
 
 
 97
 98	mutex_lock(&tps65912->io_mutex);
 
 
 99
100	data = tps65912_read(tps65912, reg);
101	if (data < 0)
102		dev_err(tps65912->dev, "Read from reg 0x%x failed\n", reg);
 
103
104	mutex_unlock(&tps65912->io_mutex);
105	return data;
106}
107EXPORT_SYMBOL_GPL(tps65912_reg_read);
 
 
 
108
109int tps65912_reg_write(struct tps65912 *tps65912, u8 reg, u8 val)
110{
111	int err;
112
113	mutex_lock(&tps65912->io_mutex);
114
115	err = tps65912_write(tps65912, reg, val);
116	if (err < 0)
117		dev_err(tps65912->dev, "Write for reg 0x%x failed\n", reg);
118
119	mutex_unlock(&tps65912->io_mutex);
120	return err;
121}
122EXPORT_SYMBOL_GPL(tps65912_reg_write);
123
124int tps65912_device_init(struct tps65912 *tps65912)
125{
126	struct tps65912_board *pmic_plat_data = tps65912->dev->platform_data;
127	struct tps65912_platform_data *init_data;
128	int ret, dcdc_avs, value;
129
130	init_data = kzalloc(sizeof(struct tps65912_platform_data), GFP_KERNEL);
131	if (init_data == NULL)
132		return -ENOMEM;
133
134	init_data->irq = pmic_plat_data->irq;
135	init_data->irq_base = pmic_plat_data->irq;
136
137	mutex_init(&tps65912->io_mutex);
138	dev_set_drvdata(tps65912->dev, tps65912);
139
140	dcdc_avs = (pmic_plat_data->is_dcdc1_avs << 0 |
141			pmic_plat_data->is_dcdc2_avs  << 1 |
142				pmic_plat_data->is_dcdc3_avs << 2 |
143					pmic_plat_data->is_dcdc4_avs << 3);
144	if (dcdc_avs) {
145		tps65912->read(tps65912, TPS65912_I2C_SPI_CFG, 1, &value);
146		dcdc_avs |= value;
147		tps65912->write(tps65912, TPS65912_I2C_SPI_CFG, 1, &dcdc_avs);
148	}
149
150	ret = mfd_add_devices(tps65912->dev, -1,
151			      tps65912s, ARRAY_SIZE(tps65912s),
152			      NULL, 0);
153	if (ret < 0)
154		goto err;
155
156	ret = tps65912_irq_init(tps65912, init_data->irq, init_data);
157	if (ret < 0)
158		goto err;
159
160	return ret;
161
162err:
163	kfree(init_data);
164	mfd_remove_devices(tps65912->dev);
165	kfree(tps65912);
166	return ret;
167}
 
168
169void tps65912_device_exit(struct tps65912 *tps65912)
170{
171	mfd_remove_devices(tps65912->dev);
172	kfree(tps65912);
 
173}
 
174
175MODULE_AUTHOR("Margarita Olaya	<magi@slimlogic.co.uk>");
176MODULE_DESCRIPTION("TPS65912x chip family multi-function driver");
177MODULE_LICENSE("GPL");
v5.14.15
  1/*
  2 * Core functions for TI TPS65912x PMICs
  3 *
  4 * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com/
  5 *	Andrew F. Davis <afd@ti.com>
  6 *
  7 * This program is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU General Public License version 2 as
  9 * published by the Free Software Foundation.
 10 *
 11 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
 12 * kind, whether expressed or implied; without even the implied warranty
 13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU General Public License version 2 for more details.
 15 *
 16 * Based on the TPS65218 driver and the previous TPS65912 driver by
 17 * Margarita Olaya Cabrera <magi@slimlogic.co.uk>
 18 */
 19
 20#include <linux/interrupt.h>
 
 
 
 
 21#include <linux/mfd/core.h>
 22#include <linux/module.h>
 23
 24#include <linux/mfd/tps65912.h>
 25
 26static const struct mfd_cell tps65912_cells[] = {
 27	{ .name = "tps65912-regulator", },
 28	{ .name = "tps65912-gpio", },
 
 29};
 30
 31static const struct regmap_irq tps65912_irqs[] = {
 32	/* INT_STS IRQs */
 33	REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_F, 0, TPS65912_INT_STS_PWRHOLD_F),
 34	REGMAP_IRQ_REG(TPS65912_IRQ_VMON, 0, TPS65912_INT_STS_VMON),
 35	REGMAP_IRQ_REG(TPS65912_IRQ_PWRON, 0, TPS65912_INT_STS_PWRON),
 36	REGMAP_IRQ_REG(TPS65912_IRQ_PWRON_LP, 0, TPS65912_INT_STS_PWRON_LP),
 37	REGMAP_IRQ_REG(TPS65912_IRQ_PWRHOLD_R, 0, TPS65912_INT_STS_PWRHOLD_R),
 38	REGMAP_IRQ_REG(TPS65912_IRQ_HOTDIE, 0, TPS65912_INT_STS_HOTDIE),
 39	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_R, 0, TPS65912_INT_STS_GPIO1_R),
 40	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO1_F, 0, TPS65912_INT_STS_GPIO1_F),
 41	/* INT_STS2 IRQs */
 42	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_R, 1, TPS65912_INT_STS2_GPIO2_R),
 43	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO2_F, 1, TPS65912_INT_STS2_GPIO2_F),
 44	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_R, 1, TPS65912_INT_STS2_GPIO3_R),
 45	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO3_F, 1, TPS65912_INT_STS2_GPIO3_F),
 46	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_R, 1, TPS65912_INT_STS2_GPIO4_R),
 47	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO4_F, 1, TPS65912_INT_STS2_GPIO4_F),
 48	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_R, 1, TPS65912_INT_STS2_GPIO5_R),
 49	REGMAP_IRQ_REG(TPS65912_IRQ_GPIO5_F, 1, TPS65912_INT_STS2_GPIO5_F),
 50	/* INT_STS3 IRQs */
 51	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC1, 2, TPS65912_INT_STS3_PGOOD_DCDC1),
 52	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC2, 2, TPS65912_INT_STS3_PGOOD_DCDC2),
 53	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC3, 2, TPS65912_INT_STS3_PGOOD_DCDC3),
 54	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_DCDC4, 2, TPS65912_INT_STS3_PGOOD_DCDC4),
 55	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO1, 2, TPS65912_INT_STS3_PGOOD_LDO1),
 56	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO2, 2, TPS65912_INT_STS3_PGOOD_LDO2),
 57	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO3, 2, TPS65912_INT_STS3_PGOOD_LDO3),
 58	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO4, 2, TPS65912_INT_STS3_PGOOD_LDO4),
 59	/* INT_STS4 IRQs */
 60	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO5, 3, TPS65912_INT_STS4_PGOOD_LDO5),
 61	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO6, 3, TPS65912_INT_STS4_PGOOD_LDO6),
 62	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO7, 3, TPS65912_INT_STS4_PGOOD_LDO7),
 63	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO8, 3, TPS65912_INT_STS4_PGOOD_LDO8),
 64	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO9, 3, TPS65912_INT_STS4_PGOOD_LDO9),
 65	REGMAP_IRQ_REG(TPS65912_IRQ_PGOOD_LDO10, 3, TPS65912_INT_STS4_PGOOD_LDO10),
 66};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 67
 68static struct regmap_irq_chip tps65912_irq_chip = {
 69	.name = "tps65912",
 70	.irqs = tps65912_irqs,
 71	.num_irqs = ARRAY_SIZE(tps65912_irqs),
 72	.num_regs = 4,
 73	.irq_reg_stride = 2,
 74	.mask_base = TPS65912_INT_MSK,
 75	.status_base = TPS65912_INT_STS,
 76	.ack_base = TPS65912_INT_STS,
 77	.init_ack_masked = true,
 78};
 79
 80static const struct regmap_range tps65912_yes_ranges[] = {
 81	regmap_reg_range(TPS65912_INT_STS, TPS65912_GPIO5),
 82};
 83
 84static const struct regmap_access_table tps65912_volatile_table = {
 85	.yes_ranges = tps65912_yes_ranges,
 86	.n_yes_ranges = ARRAY_SIZE(tps65912_yes_ranges),
 87};
 88
 89const struct regmap_config tps65912_regmap_config = {
 90	.reg_bits = 8,
 91	.val_bits = 8,
 92	.cache_type = REGCACHE_RBTREE,
 93	.volatile_table = &tps65912_volatile_table,
 94};
 95EXPORT_SYMBOL_GPL(tps65912_regmap_config);
 96
 97int tps65912_device_init(struct tps65912 *tps)
 98{
 99	int ret;
 
 
 
 
 
 
100
101	ret = regmap_add_irq_chip(tps->regmap, tps->irq, IRQF_ONESHOT, 0,
102				  &tps65912_irq_chip, &tps->irq_data);
103	if (ret)
104		return ret;
105
106	ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65912_cells,
107			      ARRAY_SIZE(tps65912_cells), NULL, 0,
108			      regmap_irq_get_domain(tps->irq_data));
109	if (ret) {
110		regmap_del_irq_chip(tps->irq, tps->irq_data);
111		return ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112	}
113
114	return 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115}
116EXPORT_SYMBOL_GPL(tps65912_device_init);
117
118int tps65912_device_exit(struct tps65912 *tps)
119{
120	regmap_del_irq_chip(tps->irq, tps->irq_data);
121
122	return 0;
123}
124EXPORT_SYMBOL_GPL(tps65912_device_exit);
125
126MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
127MODULE_DESCRIPTION("TPS65912x MFD Driver");
128MODULE_LICENSE("GPL v2");