Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1478a316 authored by John Beckett's avatar John Beckett Committed by Lee Jones
Browse files

mfd: ab8500-debugfs: Export all AB8500 ADCs as debugfs nodes



Allow a user to take a glimpse into the inner workings of the
AB8500 Analogue-to-Digital Converters, via debugfs.

Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarJohn Beckett <john.beckett@stericsson.com>
Reviewed-by: default avatarMattias WALLIN <mattias.wallin@stericsson.com>
parent 0fbce76e
Loading
Loading
Loading
Loading
+465 −21
Original line number Original line Diff line number Diff line
@@ -82,7 +82,7 @@
#include <linux/slab.h>
#include <linux/slab.h>


#include <linux/mfd/abx500.h>
#include <linux/mfd/abx500.h>
#include <linux/mfd/abx500/ab8500.h>
#include <linux/mfd/abx500/ab8500-gpadc.h>


#ifdef CONFIG_DEBUG_FS
#ifdef CONFIG_DEBUG_FS
#include <linux/string.h>
#include <linux/string.h>
@@ -143,6 +143,7 @@ static struct hwreg_cfg hwreg_cfg = {
};
};


#define AB8500_NAME_STRING "ab8500"
#define AB8500_NAME_STRING "ab8500"
#define AB8500_ADC_NAME_STRING "gpadc"
#define AB8500_NUM_BANKS 22
#define AB8500_NUM_BANKS 22


#define AB8500_REV_REG 0x80
#define AB8500_REV_REG 0x80
@@ -672,6 +673,382 @@ static int ab8500_hwreg_open(struct inode *inode, struct file *file)
	return single_open(file, ab8500_hwreg_print, inode->i_private);
	return single_open(file, ab8500_hwreg_print, inode->i_private);
}
}


static int ab8500_gpadc_bat_ctrl_print(struct seq_file *s, void *p)
{
	int bat_ctrl_raw;
	int bat_ctrl_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	bat_ctrl_raw = ab8500_gpadc_read_raw(gpadc, BAT_CTRL);
	bat_ctrl_convert = ab8500_gpadc_ad_to_voltage(gpadc,
			BAT_CTRL, bat_ctrl_raw);

	return seq_printf(s, "%d,0x%X\n",
			bat_ctrl_convert, bat_ctrl_raw);
}

static int ab8500_gpadc_bat_ctrl_open(struct inode *inode, struct file *file)
{
	return single_open(file, ab8500_gpadc_bat_ctrl_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_bat_ctrl_fops = {
	.open = ab8500_gpadc_bat_ctrl_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_btemp_ball_print(struct seq_file *s, void *p)
{
	int btemp_ball_raw;
	int btemp_ball_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	btemp_ball_raw = ab8500_gpadc_read_raw(gpadc, BTEMP_BALL);
	btemp_ball_convert = ab8500_gpadc_ad_to_voltage(gpadc, BTEMP_BALL,
			btemp_ball_raw);

	return seq_printf(s,
			"%d,0x%X\n", btemp_ball_convert, btemp_ball_raw);
}

static int ab8500_gpadc_btemp_ball_open(struct inode *inode,
		struct file *file)
{
	return single_open(file, ab8500_gpadc_btemp_ball_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_btemp_ball_fops = {
	.open = ab8500_gpadc_btemp_ball_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_main_charger_v_print(struct seq_file *s, void *p)
{
	int main_charger_v_raw;
	int main_charger_v_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	main_charger_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_V);
	main_charger_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
			MAIN_CHARGER_V, main_charger_v_raw);

	return seq_printf(s, "%d,0x%X\n",
			main_charger_v_convert, main_charger_v_raw);
}

static int ab8500_gpadc_main_charger_v_open(struct inode *inode,
		struct file *file)
{
	return single_open(file, ab8500_gpadc_main_charger_v_print,
			inode->i_private);
}

static const struct file_operations ab8500_gpadc_main_charger_v_fops = {
	.open = ab8500_gpadc_main_charger_v_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_acc_detect1_print(struct seq_file *s, void *p)
{
	int acc_detect1_raw;
	int acc_detect1_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	acc_detect1_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT1);
	acc_detect1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ACC_DETECT1,
			acc_detect1_raw);

	return seq_printf(s, "%d,0x%X\n",
			acc_detect1_convert, acc_detect1_raw);
}

static int ab8500_gpadc_acc_detect1_open(struct inode *inode,
		struct file *file)
{
	return single_open(file, ab8500_gpadc_acc_detect1_print,
			inode->i_private);
}

static const struct file_operations ab8500_gpadc_acc_detect1_fops = {
	.open = ab8500_gpadc_acc_detect1_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_acc_detect2_print(struct seq_file *s, void *p)
{
	int acc_detect2_raw;
	int acc_detect2_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	acc_detect2_raw = ab8500_gpadc_read_raw(gpadc, ACC_DETECT2);
	acc_detect2_convert = ab8500_gpadc_ad_to_voltage(gpadc,
	    ACC_DETECT2, acc_detect2_raw);

	return seq_printf(s, "%d,0x%X\n",
			acc_detect2_convert, acc_detect2_raw);
}

static int ab8500_gpadc_acc_detect2_open(struct inode *inode,
		struct file *file)
{
	return single_open(file, ab8500_gpadc_acc_detect2_print,
	    inode->i_private);
}

static const struct file_operations ab8500_gpadc_acc_detect2_fops = {
	.open = ab8500_gpadc_acc_detect2_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_aux1_print(struct seq_file *s, void *p)
{
	int aux1_raw;
	int aux1_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	aux1_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX1);
	aux1_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX1,
			aux1_raw);

	return seq_printf(s, "%d,0x%X\n",
			aux1_convert, aux1_raw);
}

static int ab8500_gpadc_aux1_open(struct inode *inode, struct file *file)
{
	return single_open(file, ab8500_gpadc_aux1_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_aux1_fops = {
	.open = ab8500_gpadc_aux1_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_aux2_print(struct seq_file *s, void *p)
{
	int aux2_raw;
	int aux2_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	aux2_raw = ab8500_gpadc_read_raw(gpadc, ADC_AUX2);
	aux2_convert = ab8500_gpadc_ad_to_voltage(gpadc, ADC_AUX2,
			aux2_raw);

	return seq_printf(s, "%d,0x%X\n",
			aux2_convert, aux2_raw);
}

static int ab8500_gpadc_aux2_open(struct inode *inode, struct file *file)
{
	return single_open(file, ab8500_gpadc_aux2_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_aux2_fops = {
	.open = ab8500_gpadc_aux2_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_main_bat_v_print(struct seq_file *s, void *p)
{
	int main_bat_v_raw;
	int main_bat_v_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	main_bat_v_raw = ab8500_gpadc_read_raw(gpadc, MAIN_BAT_V);
	main_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, MAIN_BAT_V,
			main_bat_v_raw);

	return seq_printf(s, "%d,0x%X\n",
			main_bat_v_convert, main_bat_v_raw);
}

static int ab8500_gpadc_main_bat_v_open(struct inode *inode,
		struct file *file)
{
	return single_open(file, ab8500_gpadc_main_bat_v_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_main_bat_v_fops = {
	.open = ab8500_gpadc_main_bat_v_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_vbus_v_print(struct seq_file *s, void *p)
{
	int vbus_v_raw;
	int vbus_v_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	vbus_v_raw = ab8500_gpadc_read_raw(gpadc, VBUS_V);
	vbus_v_convert = ab8500_gpadc_ad_to_voltage(gpadc, VBUS_V,
			vbus_v_raw);

	return seq_printf(s, "%d,0x%X\n",
			vbus_v_convert, vbus_v_raw);
}

static int ab8500_gpadc_vbus_v_open(struct inode *inode, struct file *file)
{
	return single_open(file, ab8500_gpadc_vbus_v_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_vbus_v_fops = {
	.open = ab8500_gpadc_vbus_v_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_main_charger_c_print(struct seq_file *s, void *p)
{
	int main_charger_c_raw;
	int main_charger_c_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	main_charger_c_raw = ab8500_gpadc_read_raw(gpadc, MAIN_CHARGER_C);
	main_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
			MAIN_CHARGER_C, main_charger_c_raw);

	return seq_printf(s, "%d,0x%X\n",
			main_charger_c_convert, main_charger_c_raw);
}

static int ab8500_gpadc_main_charger_c_open(struct inode *inode,
		struct file *file)
{
	return single_open(file, ab8500_gpadc_main_charger_c_print,
			inode->i_private);
}

static const struct file_operations ab8500_gpadc_main_charger_c_fops = {
	.open = ab8500_gpadc_main_charger_c_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_usb_charger_c_print(struct seq_file *s, void *p)
{
	int usb_charger_c_raw;
	int usb_charger_c_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	usb_charger_c_raw = ab8500_gpadc_read_raw(gpadc, USB_CHARGER_C);
	usb_charger_c_convert = ab8500_gpadc_ad_to_voltage(gpadc,
	    USB_CHARGER_C, usb_charger_c_raw);

	return seq_printf(s, "%d,0x%X\n",
			usb_charger_c_convert, usb_charger_c_raw);
}

static int ab8500_gpadc_usb_charger_c_open(struct inode *inode,
		struct file *file)
{
	return single_open(file, ab8500_gpadc_usb_charger_c_print,
	    inode->i_private);
}

static const struct file_operations ab8500_gpadc_usb_charger_c_fops = {
	.open = ab8500_gpadc_usb_charger_c_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_bk_bat_v_print(struct seq_file *s, void *p)
{
	int bk_bat_v_raw;
	int bk_bat_v_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	bk_bat_v_raw = ab8500_gpadc_read_raw(gpadc, BK_BAT_V);
	bk_bat_v_convert = ab8500_gpadc_ad_to_voltage(gpadc,
			BK_BAT_V, bk_bat_v_raw);

	return seq_printf(s, "%d,0x%X\n",
			bk_bat_v_convert, bk_bat_v_raw);
}

static int ab8500_gpadc_bk_bat_v_open(struct inode *inode, struct file *file)
{
	return single_open(file, ab8500_gpadc_bk_bat_v_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_bk_bat_v_fops = {
	.open = ab8500_gpadc_bk_bat_v_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

static int ab8500_gpadc_die_temp_print(struct seq_file *s, void *p)
{
	int die_temp_raw;
	int die_temp_convert;
	struct ab8500_gpadc *gpadc;

	gpadc = ab8500_gpadc_get();
	die_temp_raw = ab8500_gpadc_read_raw(gpadc, DIE_TEMP);
	die_temp_convert = ab8500_gpadc_ad_to_voltage(gpadc, DIE_TEMP,
			die_temp_raw);

	return seq_printf(s, "%d,0x%X\n",
			die_temp_convert, die_temp_raw);
}

static int ab8500_gpadc_die_temp_open(struct inode *inode, struct file *file)
{
	return single_open(file, ab8500_gpadc_die_temp_print, inode->i_private);
}

static const struct file_operations ab8500_gpadc_die_temp_fops = {
	.open = ab8500_gpadc_die_temp_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
	.owner = THIS_MODULE,
};

/*
/*
 * return length of an ASCII numerical value, 0 is string is not a
 * return length of an ASCII numerical value, 0 is string is not a
 * numerical value.
 * numerical value.
@@ -1042,6 +1419,7 @@ static const struct file_operations ab8500_hwreg_fops = {
};
};


static struct dentry *ab8500_dir;
static struct dentry *ab8500_dir;
static struct dentry *ab8500_gpadc_dir;


static int ab8500_debug_probe(struct platform_device *plf)
static int ab8500_debug_probe(struct platform_device *plf)
{
{
@@ -1067,42 +1445,108 @@ static int ab8500_debug_probe(struct platform_device *plf)
	if (!ab8500_dir)
	if (!ab8500_dir)
		goto err;
		goto err;


	file = debugfs_create_file("all-bank-registers",
	ab8500_gpadc_dir = debugfs_create_dir(AB8500_ADC_NAME_STRING,
		S_IRUGO, ab8500_dir, &plf->dev, &ab8500_registers_fops);
	    ab8500_dir);
	if (!ab8500_gpadc_dir)
		goto err;

	file = debugfs_create_file("all-bank-registers", S_IRUGO,
	    ab8500_dir, &plf->dev, &ab8500_registers_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("register-bank", (S_IRUGO | S_IWUSR),
	    ab8500_dir, &plf->dev, &ab8500_bank_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("register-address", (S_IRUGO | S_IWUSR),
	    ab8500_dir, &plf->dev, &ab8500_address_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("register-value", (S_IRUGO | S_IWUSR),
	    ab8500_dir, &plf->dev, &ab8500_val_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("irq-subscribe", (S_IRUGO | S_IWUSR),
	    ab8500_dir, &plf->dev, &ab8500_subscribe_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("irq-unsubscribe", (S_IRUGO | S_IWUSR),
	    ab8500_dir, &plf->dev, &ab8500_unsubscribe_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("hwreg", (S_IRUGO | S_IWUSR),
	    ab8500_dir, &plf->dev, &ab8500_hwreg_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("bat_ctrl", (S_IRUGO | S_IWUSR),
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bat_ctrl_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("btemp_ball", (S_IRUGO | S_IWUSR),
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_btemp_ball_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("main_charger_v", (S_IRUGO | S_IWUSR),
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_v_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("acc_detect1", (S_IRUGO | S_IWUSR),
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect1_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("acc_detect2", (S_IRUGO | S_IWUSR),
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_acc_detect2_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("adc_aux1", (S_IRUGO | S_IWUSR),
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux1_fops);
	if (!file)
		goto err;

	file = debugfs_create_file("adc_aux2", (S_IRUGO | S_IWUSR),
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_aux2_fops);
	if (!file)
	if (!file)
		goto err;
		goto err;


	file = debugfs_create_file("register-bank",
	file = debugfs_create_file("main_bat_v", (S_IRUGO | S_IWUSR),
		(S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_bank_fops);
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_bat_v_fops);
	if (!file)
	if (!file)
		goto err;
		goto err;


	file = debugfs_create_file("register-address",
	file = debugfs_create_file("vbus_v", (S_IRUGO | S_IWUSR),
		(S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev,
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_vbus_v_fops);
		&ab8500_address_fops);
	if (!file)
	if (!file)
		goto err;
		goto err;


	file = debugfs_create_file("register-value",
	file = debugfs_create_file("main_charger_c", (S_IRUGO | S_IWUSR),
		(S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev, &ab8500_val_fops);
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_main_charger_c_fops);
	if (!file)
	if (!file)
		goto err;
		goto err;


	file = debugfs_create_file("irq-subscribe",
	file = debugfs_create_file("usb_charger_c", (S_IRUGO | S_IWUSR),
		(S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev,
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_usb_charger_c_fops);
		&ab8500_subscribe_fops);
	if (!file)
	if (!file)
		goto err;
		goto err;


	file = debugfs_create_file("irq-unsubscribe",
	file = debugfs_create_file("bk_bat_v", (S_IRUGO | S_IWUSR),
		(S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev,
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_bk_bat_v_fops);
		&ab8500_unsubscribe_fops);
	if (!file)
	if (!file)
		goto err;
		goto err;


	file = debugfs_create_file("hwreg",
	file = debugfs_create_file("die_temp", (S_IRUGO | S_IWUSR),
		(S_IRUGO | S_IWUSR), ab8500_dir, &plf->dev,
	    ab8500_gpadc_dir, &plf->dev, &ab8500_gpadc_die_temp_fops);
		&ab8500_hwreg_fops);
	if (!file)
	if (!file)
		goto err;
		goto err;