Using a Mux to switch between reading and driving a wire
You want a tristate IO buffer, not a mux.  This sort of thing is done in Verilog all the time:

module tristate(pin, in, out, oe);
    inout wire pin;
    output wire in;
    input wire out;
    input wire oe;

    assign in = pin;
    assign pin = oe ? out : 1'bz;
endmodule