How to define/make a micro controller's pin as open drain?
Does any pin of a micro controller can be used in open drain configuration?
In the datasheet of a MCU, you can see if an GPIO pin is capable to be push-pull, open drain output. If so, you can configure the behaviour through registers. Most MCU manufacturers offer macros or functions to set the inputs and outputs correctly.
If i define a GPIO pin as an input pin, Can I use this pin in open drain configuration?
The open drain configuration itself does not influence the input. Furthermore, you can emulate an open drain (open collector) output: Set the (push-pull) output to low for OUTPUT LOW. and switch the data direction from output to input direction for an emulated OUTPUT HIGH.
Does it mandatory to define a pin as output for using it in open drain configuration?
You may define a GPIO to open-drain, e.g. use it as normal input, and switch to open-drain when changing the data direction.