aboutsummaryrefslogtreecommitdiff
path: root/drivers/mfd/pcf50606-gpo.c
blob: 3510f8b48e9049d63e8c09a2c7ab29dbee7fcf7b (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
/* Philips PCF50606 GPO Driver
 *
 * (C) 2006-2008 by Openmoko, Inc.
 * Author: Balaji Rao <balajirrao@openmoko.org>
 * All rights reserved.
 *
 * Broken down from monstrous PCF50606 driver mainly by
 * Harald Welte, Andy Green Werner Almesberger and Matt Hsu
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 */

#include <linux/kernel.h>

#include <linux/mfd/pcf50606/core.h>
#include <linux/mfd/pcf50606/gpo.h>

void pcf50606_gpo_set_active(struct pcf50606 *pcf, int gpo, int val)
{
	u8 reg, value, mask;

	reg = gpo;
	value = val;
	mask = 0x07;

	if (gpo == PCF50606_GPO2) {
		value = val << 4;
		mask = 0x07 << 4;
	}
	pcf50606_reg_set_bit_mask(pcf, reg, mask, value);
}
EXPORT_SYMBOL_GPL(pcf50606_gpo_set_active);

int pcf50606_gpo_get_active(struct pcf50606 *pcf, int gpo)
{
	u8 reg, value, shift = 0;

	reg = gpo;
	if (gpo == PCF50606_GPO2)
		shift = 4;
	
	value = pcf50606_reg_read(pcf, reg);

	return (value >> shift) & 0x07;
}
EXPORT_SYMBOL_GPL(pcf50606_gpo_get_active);

void pcf50606_gpo_set_standby(struct pcf50606 *pcf, int gpo, int val)
{
	u8 reg;

	if (gpo == PCF50606_GPO1 || gpo == PCF50606_GPO2) {
		dev_err(pcf->dev, "Can't set standby settings for GPO[12]n");
		return;
	}

	reg = gpo;

	pcf50606_reg_set_bit_mask(pcf, gpo, 0x07 << 3, val);
}
EXPORT_SYMBOL_GPL(pcf50606_gpo_set_standby);

int pcf50606_gpo_get_standby(struct pcf50606 *pcf, int gpo)
{
	u8 reg, value;

	if (gpo == PCF50606_GPO1 || gpo == PCF50606_GPO2) {
		dev_err(pcf->dev, "Can't get standby settings for GPO[12]n");
		return -EINVAL;
	}

	reg = gpo;
	value = pcf50606_reg_read(pcf, reg);

	return (value >> 3) & 0x07;
}
EXPORT_SYMBOL_GPL(pcf50606_gpo_get_standby);

void pcf50606_gpo_invert_set(struct pcf50606 *pcf, int gpo, int invert)
{
	u8 reg, value, mask;

	reg = gpo;
	value = !!invert << 6;
	mask = 0x01 << 6;

	if (gpo == PCF50606_GPO1) {
		mask = 0x01 << 4;
		value = !!invert << 4;
	}
	else if (gpo == PCF50606_GPO2) {
		mask = 0x01 << 7;
		value = !!invert << 7;
	}

	pcf50606_reg_set_bit_mask(pcf, reg, mask, value);
}
EXPORT_SYMBOL_GPL(pcf50606_gpo_invert_set);

int pcf50606_gpo_invert_get(struct pcf50606 *pcf, int gpo)
{
	u8 reg, value, shift;

	reg = gpo;
	shift = 6;

	if (gpo == PCF50606_GPO1)
		shift = 4;
	else if (gpo == PCF50606_GPO2)
		shift = 7;

	value =  pcf50606_reg_read(pcf, reg);

	return (value >> shift) & 0x01;
}
EXPORT_SYMBOL_GPL(pcf50606_gpo_invert_get);