{
        struct thermal_cooling_device *cdev;
        struct thermal_zone_device *pos = NULL;
+       unsigned long current_state;
        int id, ret;
 
        if (!ops || !ops->get_max_state || !ops->get_cur_state ||
        if (ret)
                goto out_cdev_type;
 
+       ret = cdev->ops->get_cur_state(cdev, ¤t_state);
+       if (ret)
+               goto out_cdev_type;
+
        thermal_cooling_device_setup_sysfs(cdev);
 
        ret = dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
                return ERR_PTR(ret);
        }
 
+       thermal_debug_cdev_add(cdev, current_state);
+
        /* Add 'this' new cdev to the global cdev list */
        mutex_lock(&thermal_list_lock);
 
 
        mutex_unlock(&thermal_list_lock);
 
-       thermal_debug_cdev_add(cdev);
-
        return cdev;
 
 out_cooling_dev:
 
  * Allocates a cooling device object for debug, initializes the
  * statistics and create the entries in sysfs.
  * @cdev: a pointer to a cooling device
+ * @state: current state of the cooling device
  */
-void thermal_debug_cdev_add(struct thermal_cooling_device *cdev)
+void thermal_debug_cdev_add(struct thermal_cooling_device *cdev, int state)
 {
        struct thermal_debugfs *thermal_dbg;
        struct cdev_debugfs *cdev_dbg;
                INIT_LIST_HEAD(&cdev_dbg->durations[i]);
        }
 
-       cdev_dbg->current_state = 0;
+       cdev_dbg->current_state = state;
        cdev_dbg->timestamp = ktime_get();
 
+       /*
+        * Create a record for the initial cooling device state, so its
+        * duration will be printed by cdev_dt_seq_show() as expected if it
+        * runs before the first state transition.
+        */
+       thermal_debugfs_cdev_record_get(thermal_dbg, cdev_dbg->durations, state);
+
        debugfs_create_file("trans_table", 0400, thermal_dbg->d_top,
                            thermal_dbg, &tt_fops);
 
 
 
 #ifdef CONFIG_THERMAL_DEBUGFS
 void thermal_debug_init(void);
-void thermal_debug_cdev_add(struct thermal_cooling_device *cdev);
+void thermal_debug_cdev_add(struct thermal_cooling_device *cdev, int state);
 void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev);
 void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev, int state);
 void thermal_debug_tz_add(struct thermal_zone_device *tz);
 void thermal_debug_update_trip_stats(struct thermal_zone_device *tz);
 #else
 static inline void thermal_debug_init(void) {}
-static inline void thermal_debug_cdev_add(struct thermal_cooling_device *cdev) {}
+static inline void thermal_debug_cdev_add(struct thermal_cooling_device *cdev, int state) {}
 static inline void thermal_debug_cdev_remove(struct thermal_cooling_device *cdev) {}
 static inline void thermal_debug_cdev_state_update(const struct thermal_cooling_device *cdev,
                                                   int state) {}