13 #include <linux/kernel.h>
14 #include <linux/module.h>
16 #include <linux/i2c.h>
22 #include <linux/slab.h>
26 #define FSA9480_REG_DEVID 0x01
27 #define FSA9480_REG_CTRL 0x02
28 #define FSA9480_REG_INT1 0x03
29 #define FSA9480_REG_INT2 0x04
30 #define FSA9480_REG_INT1_MASK 0x05
31 #define FSA9480_REG_INT2_MASK 0x06
32 #define FSA9480_REG_ADC 0x07
33 #define FSA9480_REG_TIMING1 0x08
34 #define FSA9480_REG_TIMING2 0x09
35 #define FSA9480_REG_DEV_T1 0x0a
36 #define FSA9480_REG_DEV_T2 0x0b
37 #define FSA9480_REG_BTN1 0x0c
38 #define FSA9480_REG_BTN2 0x0d
39 #define FSA9480_REG_CK 0x0e
40 #define FSA9480_REG_CK_INT1 0x0f
41 #define FSA9480_REG_CK_INT2 0x10
42 #define FSA9480_REG_CK_INTMASK1 0x11
43 #define FSA9480_REG_CK_INTMASK2 0x12
44 #define FSA9480_REG_MANSW1 0x13
45 #define FSA9480_REG_MANSW2 0x14
48 #define CON_SWITCH_OPEN (1 << 4)
49 #define CON_RAW_DATA (1 << 3)
50 #define CON_MANUAL_SW (1 << 2)
51 #define CON_WAIT (1 << 1)
52 #define CON_INT_MASK (1 << 0)
53 #define CON_MASK (CON_SWITCH_OPEN | CON_RAW_DATA | \
54 CON_MANUAL_SW | CON_WAIT)
57 #define DEV_USB_OTG (1 << 7)
58 #define DEV_DEDICATED_CHG (1 << 6)
59 #define DEV_USB_CHG (1 << 5)
60 #define DEV_CAR_KIT (1 << 4)
61 #define DEV_UART (1 << 3)
62 #define DEV_USB (1 << 2)
63 #define DEV_AUDIO_2 (1 << 1)
64 #define DEV_AUDIO_1 (1 << 0)
66 #define DEV_T1_USB_MASK (DEV_USB_OTG | DEV_USB)
67 #define DEV_T1_UART_MASK (DEV_UART)
68 #define DEV_T1_CHARGER_MASK (DEV_DEDICATED_CHG | DEV_USB_CHG)
71 #define DEV_AV (1 << 6)
72 #define DEV_TTY (1 << 5)
73 #define DEV_PPD (1 << 4)
74 #define DEV_JIG_UART_OFF (1 << 3)
75 #define DEV_JIG_UART_ON (1 << 2)
76 #define DEV_JIG_USB_OFF (1 << 1)
77 #define DEV_JIG_USB_ON (1 << 0)
79 #define DEV_T2_USB_MASK (DEV_JIG_USB_OFF | DEV_JIG_USB_ON)
80 #define DEV_T2_UART_MASK (DEV_JIG_UART_OFF | DEV_JIG_UART_ON)
81 #define DEV_T2_JIG_MASK (DEV_JIG_USB_OFF | DEV_JIG_USB_ON | \
82 DEV_JIG_UART_OFF | DEV_JIG_UART_ON)
89 #define SW_VAUDIO ((4 << 5) | (4 << 2))
90 #define SW_UART ((3 << 5) | (3 << 2))
91 #define SW_AUDIO ((2 << 5) | (2 << 2))
92 #define SW_DHOST ((1 << 5) | (1 << 2))
93 #define SW_AUTO ((0 << 5) | (0 << 2))
96 #define INT_DETACH (1 << 1)
97 #define INT_ATTACH (1 << 0)
117 dev_err(&client->
dev,
"%s: err %d\n", __func__, ret);
129 dev_err(&client->
dev,
"%s: err %d\n", __func__, ret);
143 dev_err(&client->
dev,
"%s: err %d\n", __func__, ret);
148 static void fsa9480_set_switch(
const char *
buf)
153 unsigned int path = 0;
157 if (!
strncmp(buf,
"VAUDIO", 6)) {
160 }
else if (!
strncmp(buf,
"UART", 4)) {
163 }
else if (!
strncmp(buf,
"AUDIO", 5)) {
166 }
else if (!
strncmp(buf,
"DHOST", 5)) {
169 }
else if (!
strncmp(buf,
"AUTO", 4)) {
182 static ssize_t fsa9480_get_switch(
char *buf)
191 return sprintf(buf,
"VAUDIO\n");
195 return sprintf(buf,
"AUDIO\n");
197 return sprintf(buf,
"DHOST\n");
201 return sprintf(buf,
"%x", value);
228 return sprintf(buf,
"CHARGER\n");
234 return sprintf(buf,
"UNKNOWN\n");
240 return fsa9480_get_switch(buf);
246 const char *buf,
size_t count)
248 fsa9480_set_switch(buf);
255 fsa9480_show_manualsw, fsa9480_set_manualsw);
257 static struct attribute *fsa9480_attributes[] = {
258 &dev_attr_device.attr,
259 &dev_attr_switch.attr,
264 .attrs = fsa9480_attributes,
269 int val1, val2,
ctrl;
277 dev_info(&client->
dev,
"intr: 0x%x, dev1: 0x%x, dev2: 0x%x\n",
290 fsa9480_write_reg(client,
301 fsa9480_write_reg(client,
307 if (val1 & DEV_T1_CHARGER_MASK) {
320 usbsw->
dev2 & DEV_T2_USB_MASK) {
327 usbsw->
dev2 & DEV_T2_UART_MASK) {
333 if (usbsw->
dev1 & DEV_T1_CHARGER_MASK) {
339 if (usbsw->
dev2 & DEV_T2_JIG_MASK) {
360 fsa9480_read_irq(client, &intr);
363 fsa9480_detect_dev(usbsw, intr);
377 fsa9480_read_irq(client, &intr);
397 "fsa9480 micro USB", usbsw);
399 dev_err(&client->
dev,
"failed to reqeust IRQ\n");
422 dev_err(&client->
dev,
"failed to allocate driver data\n");
427 usbsw->
pdata = client->
dev.platform_data;
431 i2c_set_clientdata(client, usbsw);
433 ret = fsa9480_irq_init(usbsw);
440 "failed to create fsa9480 attribute group\n");
447 if (chip->
pdata->reset_cb)
448 chip->
pdata->reset_cb();
451 fsa9480_detect_dev(usbsw, INT_ATTACH);
453 pm_runtime_set_active(&client->
dev);
484 if (device_may_wakeup(&client->
dev) && client->
irq)
485 enable_irq_wake(client->
irq);
498 if (device_may_wakeup(&client->
dev) && client->
irq)
499 disable_irq_wake(client->
irq);
513 fsa9480_detect_dev(usbsw, (dev1 || dev2) ? INT_ATTACH : INT_DETACH);
520 #define fsa9480_suspend NULL
521 #define fsa9480_resume NULL
531 static struct i2c_driver fsa9480_i2c_driver = {
535 .probe = fsa9480_probe,
539 .id_table = fsa9480_id,