diff options
author | Chanwoo Choi <cw00.choi@samsung.com> | 2013-02-12 18:42:37 -0500 |
---|---|---|
committer | Chanwoo Choi <cw00.choi@samsung.com> | 2013-02-13 17:53:55 -0500 |
commit | 07c70503a420d48402b3859e2c1c4c847a130a8b (patch) | |
tree | 569039c19135e3740fed38ead53fa30d9f9fe655 /drivers/extcon | |
parent | e3e5bc02d2365d3e09164fd9a559011399ca2a4f (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>
Diffstat (limited to 'drivers/extcon')
-rw-r--r-- | drivers/extcon/extcon-max8997.c | 62 |
1 files changed, 51 insertions, 11 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 | */ | ||
107 | static 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 | |||
97 | static int max8997_muic_handle_usb(struct max8997_muic_info *info, | 145 | static 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; |