2 * arch/arm/mach-sc/sec-switch.c
4 * c source file supporting MUIC common platform device register
6 * Copyright (C) 2014 Samsung Electronics
7 * tyung.kim <tyung.kim@samsung.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/platform_device.h>
26 #include <linux/device.h>
27 #include <linux/kernel.h>
28 #include <linux/err.h>
29 #include <linux/power_supply.h>
30 #include <linux/module.h>
31 #include <linux/usb/gadget.h>
32 #include <linux/regulator/consumer.h>
33 #include <linux/mfd/sm5701_core.h>
35 #ifdef CONFIG_TOUCHSCREEN_IMAGIS_IST30XXC
36 #include <linux/i2c/ist30xxc.h>
39 #ifdef CONFIG_TOUCHSCREEN_ZINITIX_BT432
40 #include <linux/i2c/zinitix_ts.h>
43 #ifdef CONFIG_MFD_SM5504
44 #include <linux/mfd/sm5504.h>
48 #include <linux/switch.h>
49 static struct switch_dev switch_dock = {
53 static struct switch_dev switch_usb = {
57 static struct switch_dev switch_otg = {
61 static struct switch_dev switch_jig = {
64 #endif /* CONFIG_SWITCH */
66 extern struct class *sec_class;
67 struct device *switch_device;
68 EXPORT_SYMBOL(switch_device);
70 #ifdef CONFIG_TOUCHSCREEN_IMAGIS_IST30XXC
71 struct tsp_callbacks *ist30xxc_charger_callbacks;
72 void ist30xxc_tsp_charger_infom(int cable_type)
74 if (ist30xxc_charger_callbacks && ist30xxc_charger_callbacks->inform_charger)
75 ist30xxc_charger_callbacks->inform_charger(ist30xxc_charger_callbacks, cable_type);
79 #ifdef CONFIG_TOUCHSCREEN_ZINITIX_BT432
80 struct tsp_callbacks *zinitix_charger_callbacks;
81 void zinitix_tsp_charger_infom(int cable_type)
83 if (zinitix_charger_callbacks && zinitix_charger_callbacks->inform_charger)
84 zinitix_charger_callbacks->inform_charger(zinitix_charger_callbacks, cable_type);
86 void zinitix_tsp_register_callback(struct tsp_callbacks *cb)
88 zinitix_charger_callbacks = cb;
89 pr_info("%s\n", __func__);
93 static void muic_init_cb(void)
97 pr_info("func:%s\n", __func__);
99 ret = switch_dev_register(&switch_dock);
101 pr_err("%s Failed to register dock switch(%d)\n", __func__, ret);
103 ret = switch_dev_register(&switch_usb);
105 pr_err("%s Failed to register usb switch(%d)\n", __func__, ret);
107 ret = switch_dev_register(&switch_otg);
109 pr_err("%s Failed to register otg switch(%d)\n", __func__, ret);
111 ret = switch_dev_register(&switch_jig);
113 pr_err("%s Failed to register jig switch(%d)\n", __func__, ret);
117 extern void usb_notify_cb(int plug_in);
119 static void muic_usb_cb(u8 attached)
121 pr_info("%s: usb_mode:%d\n", __func__, attached);
123 usb_notify_cb(attached);
126 switch_set_state(&switch_usb, attached);
131 static void muic_otg_cb(u8 attached)
133 pr_info("%s: otg_mode:%d\n", __func__, attached);
138 switch_set_state(&switch_otg, attached);
141 #ifdef CONFIG_MFD_SM5504
143 SM5701_set_bstout(SM5701_BSTOUT_5P0);
144 SM5701_set_operationmode(SM5701_OPERATIONMODE_OTG_ON);
147 SM5701_set_bstout(SM5701_BSTOUT_4P5);
148 SM5701_clear_operationmode(SM5701_OPERATIONMODE_OTG_ON);
155 #ifdef CONFIG_TOUCHSCREEN_IST30XXB
156 void charger_enable(int enable);
160 #ifdef CONFIG_MFD_SM5504
161 extern int current_cable_type;
164 static void muic_charger_cb(int cable_type)
166 struct power_supply *psy = power_supply_get_by_name("battery");
167 union power_supply_propval value;
169 pr_info("%s: cable type (0x%02x)\n", __func__, cable_type);
171 #ifdef CONFIG_TOUCHSCREEN_ZINITIX_BT432
172 zinitix_tsp_charger_infom(cable_type);
175 #ifdef CONFIG_MFD_SM5504
176 switch (cable_type) {
177 case MUIC_SM5504_CABLE_TYPE_NONE:
178 case MUIC_SM5504_CABLE_TYPE_UNKNOWN:
179 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
181 #ifdef CONFIG_TOUCHSCREEN_IST30XXB
184 #ifdef CONFIG_TOUCHSCREEN_IMAGIS_IST30XXC
185 ist30xxc_tsp_charger_infom(0);
188 case MUIC_SM5504_CABLE_TYPE_USB:
189 case MUIC_SM5504_CABLE_TYPE_CDP:
190 case MUIC_SM5504_CABLE_TYPE_L_USB:
191 case MUIC_SM5504_CABLE_TYPE_0x15:
192 case MUIC_SM5504_CABLE_TYPE_TYPE1_CHARGER:
193 current_cable_type = POWER_SUPPLY_TYPE_USB;
195 #ifdef CONFIG_TOUCHSCREEN_IST30XXB
198 #ifdef CONFIG_TOUCHSCREEN_IMAGIS_IST30XXC
199 ist30xxc_tsp_charger_infom(1);
202 case MUIC_SM5504_CABLE_TYPE_REGULAR_TA:
203 case MUIC_SM5504_CABLE_TYPE_ATT_TA:
204 current_cable_type = POWER_SUPPLY_TYPE_MAINS;
206 #ifdef CONFIG_TOUCHSCREEN_IST30XXB
209 #ifdef CONFIG_TOUCHSCREEN_IMAGIS_IST30XXC
210 ist30xxc_tsp_charger_infom(1);
213 case MUIC_SM5504_CABLE_TYPE_OTG:
214 #if 0 /*def CONFIG_MACH_KIRAN*/
215 current_cable_type = POWER_SUPPLY_TYPE_USB;
220 case MUIC_SM5504_CABLE_TYPE_JIG_UART_OFF_WITH_VBUS:
221 case MUIC_SM5504_CABLE_TYPE_JIG_UART_ON_WITH_VBUS:
222 current_cable_type = POWER_SUPPLY_TYPE_UARTOFF;
225 case MUIC_SM5504_CABLE_TYPE_JIG_UART_OFF:
226 case MUIC_SM5504_CABLE_TYPE_JIG_UART_ON:
227 current_cable_type = POWER_SUPPLY_TYPE_BATTERY;
230 case MUIC_SM5504_CABLE_TYPE_JIG_USB_ON:
231 case MUIC_SM5504_CABLE_TYPE_JIG_USB_OFF:
232 current_cable_type = POWER_SUPPLY_TYPE_USB;
234 #ifdef CONFIG_TOUCHSCREEN_IST30XXB
237 #ifdef CONFIG_TOUCHSCREEN_IMAGIS_IST30XXC
238 ist30xxc_tsp_charger_infom(1);
241 case MUIC_SM5504_CABLE_TYPE_0x1A:
242 case MUIC_SM5504_CABLE_TYPE_UART:
243 current_cable_type = POWER_SUPPLY_TYPE_MAINS;
245 #ifdef CONFIG_TOUCHSCREEN_IST30XXB
248 #ifdef CONFIG_TOUCHSCREEN_IMAGIS_IST30XXC
249 ist30xxc_tsp_charger_infom(1);
253 pr_err("%s: invalid type for charger:%d\n",
254 __func__, cable_type);
255 current_cable_type = POWER_SUPPLY_TYPE_UNKNOWN;
259 if (!psy || !psy->set_property)
260 pr_err("%s: fail to get battery psy\n", __func__);
262 value.intval = current_cable_type;
263 psy->set_property(psy, POWER_SUPPLY_PROP_ONLINE, &value);
271 static void muic_dock_cb(u8 type)
273 pr_info("%s: type: %d\n", __func__, type);
276 switch_set_state(&switch_dock, type);
280 bool is_jig_attached;
281 int muic_get_jig_state(void)
283 return is_jig_attached;
285 EXPORT_SYMBOL(muic_get_jig_state);
287 static void muic_set_jig_state(u8 attached)
289 pr_info("%s: attached: %d\n", __func__, attached);
290 is_jig_attached = !!attached;
293 switch_set_state(&switch_jig, !!attached);
297 struct sec_switch_data switch_data = {
298 .init_cb = muic_init_cb,
299 .dock_cb = muic_dock_cb,
300 .usb_cb = muic_usb_cb,
301 .otg_cb = muic_otg_cb,
302 .cable_chg_cb = muic_charger_cb,
303 .set_jig_state_cb = muic_set_jig_state,
306 static int __init sec_switch_init(void)
309 pr_err("%s: sec_class is null\n", __func__);
313 switch_device = device_create(sec_class, NULL, 0, NULL, "switch");
314 if (IS_ERR(switch_device)) {
315 pr_err("%s: Failed to create device(switch)!\n", __func__);
322 device_initcall(sec_switch_init);