An electronic device comprising: a connection unit comprising a first port, a second port, a third port, and a fourth port for connecting an external audio device; a codec configured to generate an audio signal transmitted to the external audio device; a first switch unit configured to, if the external audio device is electrically connected to the electronic device, connect the first port and the second port with the codec; a second switch unit configured to, if the external audio device is electrically connected to the electronic device, connect the third port and the fourth port with the codec, wherein the third port is a sideband use, SBU, 1 port of the electronic device and the fourth port is an SBU2 port of the electronic device; a third switch unit coupled between the codec and the second switch unit and configured to swap connection directions of the third port and the fourth port based on a coupling orientation of the external audio device and the electronic device, wherein, when the coupling orientation is a forward orientation, a ground, GND, port of the external audio device is connected to the third port and a microphone, MIC, port of the external audio device is connected to the fourth port, and when the coupling orientation is a reverse orientation, the GND port of the external audio device is connected to the fourth port and the MIC port of the external audio device is connected to the third port; a ground unit connected to a first wire between the second switch unit and the third port and connected to a second wire between the second switch unit and the fourth port and configured to connect one of the first wire and the second wire with a ground area of the electronic device based on the coupling orientation, wherein, when the third port is connected to the GND port of the external audio device, the first wire is connected with the ground area of the electronic device and when the fourth port is connected to the GND port of the external audio device, the second wire is connected with the ground area of the electronic device; and a processor (120, 590) configured to transmit to the third switch unit a first signal for controlling to swap the connection directions of the third port and the fourth port based on the coupling orientation and transmit to the ground unit a second signal for controlling to connect one of the first wire and the second wire with the ground area of the electronic device based on the coupling orientation. a connection unit comprising a first port, a second port, a third port, and a fourth port for connecting an external audio device; a codec configured to generate an audio signal transmitted to the external audio device; a first switch unit configured to, if the external audio device is electrically connected to the electronic device, connect the first port and the second port with the codec; a second switch unit configured to, if the external audio device is electrically connected to the electronic device, connect the third port and the fourth port with the codec, wherein the third port is a sideband use, SBU, 1 port of the electronic device and the fourth port is an SBU2 port of the electronic device; a third switch unit coupled between the codec and the second switch unit and configured to swap connection directions of the third port and the fourth port based on a coupling orientation of the external audio device and the electronic device, wherein, when the coupling orientation is a forward orientation, a ground, GND, port of the external audio device is connected to the third port and a microphone, MIC, port of the external audio device is connected to the fourth port, and when the coupling orientation is a reverse orientation, the GND port of the external audio device is connected to the fourth port and the MIC port of the external audio device is connected to the third port; a ground unit connected to a first wire between the second switch unit and the third port and connected to a second wire between the second switch unit and the fourth port and configured to connect one of the first wire and the second wire with a ground area of the electronic device based on the coupling orientation, wherein, when the third port is connected to the GND port of the external audio device, the first wire is connected with the ground area of the electronic device and when the fourth port is connected to the GND port of the external audio device, the second wire is connected with the ground area of the electronic device; and a processor (120, 590) configured to transmit to the third switch unit a first signal for controlling to swap the connection directions of the third port and the fourth port based on the coupling orientation and transmit to the ground unit a second signal for controlling to connect one of the first wire and the second wire with the ground area of the electronic device based on the coupling orientation.