Q:

How to get device from the kobject

In Linux kernel, given a kobject object how can I know is it encapsulated into the device struct?

A:

See the following LWN Article.
In summary
struct kobj_type *ktype = get_ktype(kobj);
if (ktype == &device_ktype) 
{
struct device *dev = to_dev(kobj); 
}

