aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChanwoo Choi <cw00.choi@samsung.com>2013-02-12 18:42:37 -0500
committerChanwoo Choi <cw00.choi@samsung.com>2013-02-13 17:53:55 -0500
commit07c70503a420d48402b3859e2c1c4c847a130a8b (patch)
tree569039c19135e3740fed38ead53fa30d9f9fe655
parente3e5bc02d2365d3e09164fd9a559011399ca2a4f (diff)
extcon: max8997: Remove duplicate code related to set H/W line path
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com>
-rw-r--r--drivers/extcon/extcon-max8997.c62
-rw-r--r--include/linux/mfd/max8997-private.h19
2 files changed, 69 insertions, 12 deletions
diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 0fb1d48b0741..8739b50c2b36 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -94,16 +94,61 @@ static const char *max8997_extcon_cable[] = {
94 NULL, 94 NULL,
95}; 95};
96 96
97/*
98 * max8997_muic_set_path - Set hardware line according to attached cable
99 * @info: the instance including private data of max8997 MUIC
100 * @value: the path according to attached cable
101 * @attached: the state of cable (true:attached, false:detached)
102 *
103 * The max8997 MUIC device share outside H/W line among a varity of cables,
104 * so this function set internal path of H/W line according to the type of
105 * attached cable.
106 */
107static int max8997_muic_set_path(struct max8997_muic_info *info,
108 u8 val, bool attached)
109{
110 int ret = 0;
111 u8 ctrl1, ctrl2 = 0;
112
113 if (attached)
114 ctrl1 = val;
115 else
116 ctrl1 = CONTROL1_SW_OPEN;
117
118 ret = max8997_update_reg(info->muic,
119 MAX8997_MUIC_REG_CONTROL1, ctrl1, COMP_SW_MASK);
120 if (ret < 0) {
121 dev_err(info->dev, "failed to update MUIC register\n");
122 return -EAGAIN;
123 }
124
125 if (attached)
126 ctrl2 |= CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
127 else
128 ctrl2 |= CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
129
130 ret = max8997_update_reg(info->muic,
131 MAX8997_MUIC_REG_CONTROL2, ctrl2,
132 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK);
133 if (ret < 0) {
134 dev_err(info->dev, "failed to update MUIC register\n");
135 return -EAGAIN;
136 }
137
138 dev_info(info->dev,
139 "CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
140 ctrl1, ctrl2, attached ? "attached" : "detached");
141
142 return 0;
143}
144
97static int max8997_muic_handle_usb(struct max8997_muic_info *info, 145static int max8997_muic_handle_usb(struct max8997_muic_info *info,
98 enum max8997_muic_usb_type usb_type, bool attached) 146 enum max8997_muic_usb_type usb_type, bool attached)
99{ 147{
100 int ret = 0; 148 int ret = 0;
101 149
102 if (usb_type == MAX8997_USB_HOST) { 150 if (usb_type == MAX8997_USB_HOST) {
103 /* switch to USB */ 151 ret = max8997_muic_set_path(info, CONTROL1_SW_USB, attached);
104 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
105 attached ? CONTROL1_SW_USB : CONTROL1_SW_OPEN,
106 CONTROL1_SW_MASK);
107 if (ret) { 152 if (ret) {
108 dev_err(info->dev, "failed to update muic register\n"); 153 dev_err(info->dev, "failed to update muic register\n");
109 goto out; 154 goto out;
@@ -131,10 +176,7 @@ static int max8997_muic_handle_dock(struct max8997_muic_info *info,
131{ 176{
132 int ret = 0; 177 int ret = 0;
133 178
134 /* switch to AUDIO */ 179 ret = max8997_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
135 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
136 attached ? CONTROL1_SW_AUDIO : CONTROL1_SW_OPEN,
137 CONTROL1_SW_MASK);
138 if (ret) { 180 if (ret) {
139 dev_err(info->dev, "failed to update muic register\n"); 181 dev_err(info->dev, "failed to update muic register\n");
140 goto out; 182 goto out;
@@ -161,9 +203,7 @@ static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
161 int ret = 0; 203 int ret = 0;
162 204
163 /* switch to UART */ 205 /* switch to UART */
164 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1, 206 ret = max8997_muic_set_path(info, CONTROL1_SW_UART, attached);
165 attached ? CONTROL1_SW_UART : CONTROL1_SW_OPEN,
166 CONTROL1_SW_MASK);
167 if (ret) { 207 if (ret) {
168 dev_err(info->dev, "failed to update muic register\n"); 208 dev_err(info->dev, "failed to update muic register\n");
169 goto out; 209 goto out;
diff --git a/include/linux/mfd/max8997-private.h b/include/linux/mfd/max8997-private.h
index acf42e960320..010173a92274 100644
--- a/include/linux/mfd/max8997-private.h
+++ b/include/linux/mfd/max8997-private.h
@@ -223,7 +223,7 @@ enum max8997_muic_reg {
223#define COMP2SW_SHIFT 3 223#define COMP2SW_SHIFT 3
224#define COMN1SW_MASK (0x7 << COMN1SW_SHIFT) 224#define COMN1SW_MASK (0x7 << COMN1SW_SHIFT)
225#define COMP2SW_MASK (0x7 << COMP2SW_SHIFT) 225#define COMP2SW_MASK (0x7 << COMP2SW_SHIFT)
226#define CONTROL1_SW_MASK (COMP2SW_MASK | COMN1SW_MASK) 226#define COMP_SW_MASK (COMP2SW_MASK | COMN1SW_MASK)
227 227
228#define CONTROL1_SW_USB ((1 << COMP2SW_SHIFT) \ 228#define CONTROL1_SW_USB ((1 << COMP2SW_SHIFT) \
229 | (1 << COMN1SW_SHIFT)) 229 | (1 << COMN1SW_SHIFT))
@@ -234,6 +234,23 @@ enum max8997_muic_reg {
234#define CONTROL1_SW_OPEN ((0 << COMP2SW_SHIFT) \ 234#define CONTROL1_SW_OPEN ((0 << COMP2SW_SHIFT) \
235 | (0 << COMN1SW_SHIFT)) 235 | (0 << COMN1SW_SHIFT))
236 236
237#define CONTROL2_LOWPWR_SHIFT (0)
238#define CONTROL2_ADCEN_SHIFT (1)
239#define CONTROL2_CPEN_SHIFT (2)
240#define CONTROL2_SFOUTASRT_SHIFT (3)
241#define CONTROL2_SFOUTORD_SHIFT (4)
242#define CONTROL2_ACCDET_SHIFT (5)
243#define CONTROL2_USBCPINT_SHIFT (6)
244#define CONTROL2_RCPS_SHIFT (7)
245#define CONTROL2_LOWPWR_MASK (0x1 << CONTROL2_LOWPWR_SHIFT)
246#define CONTROL2_ADCEN_MASK (0x1 << CONTROL2_ADCEN_SHIFT)
247#define CONTROL2_CPEN_MASK (0x1 << CONTROL2_CPEN_SHIFT)
248#define CONTROL2_SFOUTASRT_MASK (0x1 << CONTROL2_SFOUTASRT_SHIFT)
249#define CONTROL2_SFOUTORD_MASK (0x1 << CONTROL2_SFOUTORD_SHIFT)
250#define CONTROL2_ACCDET_MASK (0x1 << CONTROL2_ACCDET_SHIFT)
251#define CONTROL2_USBCPINT_MASK (0x1 << CONTROL2_USBCPINT_SHIFT)
252#define CONTROL2_RCPS_MASK (0x1 << CONTROL2_RCPS_SHIFT)
253
237#define MAX8997_ADC_GROUND 0x00 254#define MAX8997_ADC_GROUND 0x00
238#define MAX8997_ADC_MHL 0x01 255#define MAX8997_ADC_MHL 0x01
239#define MAX8997_ADC_JIG_USB_1 0x18 256#define MAX8997_ADC_JIG_USB_1 0x18