aboutsummaryrefslogtreecommitdiff
path: root/drivers/power/ftt_sysfs.c
blob: c1e5066ae881a512a02c33418d8cdcf1f4c90f49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <linux/platform_device.h>

#include "ftt_ctrl_comm.h"
#include "ftt_status.h"
#include "ftt_charger_v3.h"

#ifdef CONFIG_FTT_SYSFS

extern const char *get_ftt_saved_pad_type_str(struct ftt_charger_device *ftt_pdev);
extern bool is_ftt_charging(struct ftt_charger_device *ftt_pdev);
extern enum ftt_charger_status get_ftt_charger_current_status(struct ftt_charger_device *ftt_pdev);

static	ssize_t show_ftt_total	(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_total, FTT_SYS_PERMISSION, show_ftt_total, NULL);
static	ssize_t show_ftt_frequency	(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_frequency, FTT_SYS_PERMISSION, show_ftt_frequency, NULL);
static	ssize_t show_ftt_is_charging	(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_is_charging, FTT_SYS_PERMISSION, show_ftt_is_charging, NULL);
static	ssize_t show_ftt_ant_level	(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_ant_level, FTT_SYS_PERMISSION, show_ftt_ant_level, NULL);
static	ssize_t show_ftt_pad_type	(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_pad_type, FTT_SYS_PERMISSION, show_ftt_pad_type, NULL);
static	ssize_t show_ftt_status(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_status, FTT_SYS_PERMISSION, show_ftt_status, NULL);
static	ssize_t show_ftt_ver(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_ver, FTT_SYS_PERMISSION, show_ftt_ver, NULL);
static	ssize_t show_ftt_version(struct device *dev, struct device_attribute *attr, char *buf);
static	DEVICE_ATTR(ftt_version, FTT_SYS_PERMISSION, show_ftt_version, NULL);

static struct attribute *ftt_sysfs_entries[] = {
		&dev_attr_ftt_total.attr,
		&dev_attr_ftt_frequency.attr,
		&dev_attr_ftt_is_charging.attr,
		&dev_attr_ftt_ant_level.attr,
		&dev_attr_ftt_pad_type.attr,
		&dev_attr_ftt_status.attr,
		&dev_attr_ftt_ver.attr,
		&dev_attr_ftt_version.attr,
		NULL
};

struct attribute_group ftt_sysfs_attr_group = {
	.name   = NULL,
	.attrs  = ftt_sysfs_entries,
};


static	ssize_t show_ftt_total	(struct device *dev, struct device_attribute *attr, char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct ftt_charger_device *ftt_pdev = (struct ftt_charger_device *)platform_get_drvdata(pdev);
	char *ppad_type;

	ppad_type = (char *)get_ftt_saved_pad_type_str(ftt_pdev);
	if (ppad_type == NULL)
		ppad_type = "";

	return sprintf(buf,
			"PAD TYPE : %s\n"
			"PAD NUMBER : %u\n"
			"FTT Frequency : %uHz\n"
			"LEVEL : %d\n"
			, ppad_type
			,ftt_pdev->detect_pad
			,ftt_pdev->ftt_frequency
			,ftt_pdev->ant_level
			);
}


static 	ssize_t show_ftt_frequency		(struct device *dev, struct device_attribute *attr, char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct ftt_charger_device *ftt_pdev = (struct ftt_charger_device *)platform_get_drvdata(pdev);

	return sprintf(buf, "%u\n", ftt_pdev->ftt_frequency);
}

static	ssize_t show_ftt_is_charging	(struct device *dev, struct device_attribute *attr, char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct ftt_charger_device *ftt_pdev = (struct ftt_charger_device *)platform_get_drvdata(pdev);

	return sprintf(buf, "%u\n", is_ftt_charging(ftt_pdev));
}

static	ssize_t show_ftt_ant_level	(struct device *dev, struct device_attribute *attr, char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct ftt_charger_device *ftt_pdev = (struct ftt_charger_device *)platform_get_drvdata(pdev);

	return sprintf(buf, "%d\n", ftt_pdev->ant_level);
}

static	ssize_t show_ftt_pad_type	(struct device *dev, struct device_attribute *attr, char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct ftt_charger_device *ftt_pdev = (struct ftt_charger_device *)platform_get_drvdata(pdev);
	char *ppad_type;

	ppad_type = (char *)get_ftt_saved_pad_type_str(ftt_pdev);
	if (ppad_type == NULL)
		ppad_type = "";
	return sprintf(buf, "%s\n", ppad_type);
}

static	ssize_t show_ftt_status(struct device *dev, struct device_attribute *attr, char *buf)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct ftt_charger_device *ftt_pdev = (struct ftt_charger_device *)platform_get_drvdata(pdev);

	switch (get_ftt_charger_current_status(ftt_pdev)) {
	case	FTT_CHARGER_STATUS_PING_DETECT :
		return sprintf(buf, "%s\n", "DETECT");
		break;
	case	FTT_CHARGER_STATUS_PRE_CHARGING :
		return sprintf(buf, "%s\n", "PRE_CHARGING");
		break;
	case	FTT_CHARGER_STATUS_CHARGING :
		return sprintf(buf, "%s\n", "CHARGING");
		break;
	default :
		return sprintf(buf, "%s\n", "NULL");
		break;
	}

	return 0;
}

static	ssize_t show_ftt_ver(struct device *dev, struct device_attribute *attr, char *buf)
{
	return sprintf(buf, "v%u.%u.%u\n", FTT_DD_MAJOR_VERSION, FTT_DD_MINOR_VERSION_A, FTT_DD_MINOR_VERSION_B);
}

static	ssize_t show_ftt_version(struct device *dev, struct device_attribute *attr, char *buf)
{
	return sprintf(buf, "%s l%d : v%u.%u.%u ,compile : %s, %s\n", DEVICE_NAME, MAX_ANT_LEVEL, FTT_DD_MAJOR_VERSION, FTT_DD_MINOR_VERSION_A, FTT_DD_MINOR_VERSION_B, __DATE__, __TIME__);
}

#endif /* CONFIG_FTT_SYSFS */