Skip to content

Commit 45cf2ec

Browse files
Eduardo Valentinzhang-rui
authored andcommitted
thermal: core: move cooling device sysfs to thermal_sysfs.c
This is a code reorganization, simply to concentrate the sysfs handling functions in thermal_sysfs.c. This patch moves the cooling device handling functions. Cc: Zhang Rui <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Eduardo Valentin <[email protected]> Signed-off-by: Zhang Rui <[email protected]>
1 parent 99ea2ef commit 45cf2ec

File tree

3 files changed

+145
-127
lines changed

3 files changed

+145
-127
lines changed

drivers/thermal/thermal_core.c

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -798,132 +798,6 @@ int thermal_build_list_of_policies(char *buf)
798798
return count;
799799
}
800800

801-
/* sys I/F for cooling device */
802-
static ssize_t
803-
thermal_cooling_device_type_show(struct device *dev,
804-
struct device_attribute *attr, char *buf)
805-
{
806-
struct thermal_cooling_device *cdev = to_cooling_device(dev);
807-
808-
return sprintf(buf, "%s\n", cdev->type);
809-
}
810-
811-
static ssize_t
812-
thermal_cooling_device_max_state_show(struct device *dev,
813-
struct device_attribute *attr, char *buf)
814-
{
815-
struct thermal_cooling_device *cdev = to_cooling_device(dev);
816-
unsigned long state;
817-
int ret;
818-
819-
ret = cdev->ops->get_max_state(cdev, &state);
820-
if (ret)
821-
return ret;
822-
return sprintf(buf, "%ld\n", state);
823-
}
824-
825-
static ssize_t
826-
thermal_cooling_device_cur_state_show(struct device *dev,
827-
struct device_attribute *attr, char *buf)
828-
{
829-
struct thermal_cooling_device *cdev = to_cooling_device(dev);
830-
unsigned long state;
831-
int ret;
832-
833-
ret = cdev->ops->get_cur_state(cdev, &state);
834-
if (ret)
835-
return ret;
836-
return sprintf(buf, "%ld\n", state);
837-
}
838-
839-
static ssize_t
840-
thermal_cooling_device_cur_state_store(struct device *dev,
841-
struct device_attribute *attr,
842-
const char *buf, size_t count)
843-
{
844-
struct thermal_cooling_device *cdev = to_cooling_device(dev);
845-
unsigned long state;
846-
int result;
847-
848-
if (sscanf(buf, "%ld\n", &state) != 1)
849-
return -EINVAL;
850-
851-
if ((long)state < 0)
852-
return -EINVAL;
853-
854-
result = cdev->ops->set_cur_state(cdev, state);
855-
if (result)
856-
return result;
857-
return count;
858-
}
859-
860-
static struct device_attribute dev_attr_cdev_type =
861-
__ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
862-
static DEVICE_ATTR(max_state, 0444,
863-
thermal_cooling_device_max_state_show, NULL);
864-
static DEVICE_ATTR(cur_state, 0644,
865-
thermal_cooling_device_cur_state_show,
866-
thermal_cooling_device_cur_state_store);
867-
868-
static ssize_t
869-
thermal_cooling_device_trip_point_show(struct device *dev,
870-
struct device_attribute *attr, char *buf)
871-
{
872-
struct thermal_instance *instance;
873-
874-
instance =
875-
container_of(attr, struct thermal_instance, attr);
876-
877-
if (instance->trip == THERMAL_TRIPS_NONE)
878-
return sprintf(buf, "-1\n");
879-
else
880-
return sprintf(buf, "%d\n", instance->trip);
881-
}
882-
883-
static struct attribute *cooling_device_attrs[] = {
884-
&dev_attr_cdev_type.attr,
885-
&dev_attr_max_state.attr,
886-
&dev_attr_cur_state.attr,
887-
NULL,
888-
};
889-
890-
static const struct attribute_group cooling_device_attr_group = {
891-
.attrs = cooling_device_attrs,
892-
};
893-
894-
static const struct attribute_group *cooling_device_attr_groups[] = {
895-
&cooling_device_attr_group,
896-
NULL,
897-
};
898-
899-
static ssize_t
900-
thermal_cooling_device_weight_show(struct device *dev,
901-
struct device_attribute *attr, char *buf)
902-
{
903-
struct thermal_instance *instance;
904-
905-
instance = container_of(attr, struct thermal_instance, weight_attr);
906-
907-
return sprintf(buf, "%d\n", instance->weight);
908-
}
909-
910-
static ssize_t
911-
thermal_cooling_device_weight_store(struct device *dev,
912-
struct device_attribute *attr,
913-
const char *buf, size_t count)
914-
{
915-
struct thermal_instance *instance;
916-
int ret, weight;
917-
918-
ret = kstrtoint(buf, 0, &weight);
919-
if (ret)
920-
return ret;
921-
922-
instance = container_of(attr, struct thermal_instance, weight_attr);
923-
instance->weight = weight;
924-
925-
return count;
926-
}
927801
/* Device management */
928802

929803
/**
@@ -1175,7 +1049,7 @@ __thermal_cooling_device_register(struct device_node *np,
11751049
cdev->ops = ops;
11761050
cdev->updated = false;
11771051
cdev->device.class = &thermal_class;
1178-
cdev->device.groups = cooling_device_attr_groups;
1052+
thermal_cooling_device_setup_sysfs(cdev);
11791053
cdev->devdata = devdata;
11801054
dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
11811055
result = device_register(&cdev->device);

drivers/thermal/thermal_core.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ int thermal_build_list_of_policies(char *buf);
7171

7272
/* sysfs I/F */
7373
int thermal_zone_create_device_groups(struct thermal_zone_device *, int);
74+
void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *);
75+
/* used only at binding time */
76+
ssize_t
77+
thermal_cooling_device_trip_point_show(struct device *,
78+
struct device_attribute *, char *);
79+
ssize_t thermal_cooling_device_weight_show(struct device *,
80+
struct device_attribute *, char *);
81+
82+
ssize_t thermal_cooling_device_weight_store(struct device *,
83+
struct device_attribute *,
84+
const char *, size_t);
7485

7586
#ifdef CONFIG_THERMAL_GOV_STEP_WISE
7687
int thermal_gov_step_wise_register(void);

drivers/thermal/thermal_sysfs.c

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,3 +631,136 @@ int thermal_zone_create_device_groups(struct thermal_zone_device *tz,
631631

632632
return 0;
633633
}
634+
635+
/* sys I/F for cooling device */
636+
static ssize_t
637+
thermal_cooling_device_type_show(struct device *dev,
638+
struct device_attribute *attr, char *buf)
639+
{
640+
struct thermal_cooling_device *cdev = to_cooling_device(dev);
641+
642+
return sprintf(buf, "%s\n", cdev->type);
643+
}
644+
645+
static ssize_t
646+
thermal_cooling_device_max_state_show(struct device *dev,
647+
struct device_attribute *attr, char *buf)
648+
{
649+
struct thermal_cooling_device *cdev = to_cooling_device(dev);
650+
unsigned long state;
651+
int ret;
652+
653+
ret = cdev->ops->get_max_state(cdev, &state);
654+
if (ret)
655+
return ret;
656+
return sprintf(buf, "%ld\n", state);
657+
}
658+
659+
static ssize_t
660+
thermal_cooling_device_cur_state_show(struct device *dev,
661+
struct device_attribute *attr, char *buf)
662+
{
663+
struct thermal_cooling_device *cdev = to_cooling_device(dev);
664+
unsigned long state;
665+
int ret;
666+
667+
ret = cdev->ops->get_cur_state(cdev, &state);
668+
if (ret)
669+
return ret;
670+
return sprintf(buf, "%ld\n", state);
671+
}
672+
673+
static ssize_t
674+
thermal_cooling_device_cur_state_store(struct device *dev,
675+
struct device_attribute *attr,
676+
const char *buf, size_t count)
677+
{
678+
struct thermal_cooling_device *cdev = to_cooling_device(dev);
679+
unsigned long state;
680+
int result;
681+
682+
if (sscanf(buf, "%ld\n", &state) != 1)
683+
return -EINVAL;
684+
685+
if ((long)state < 0)
686+
return -EINVAL;
687+
688+
result = cdev->ops->set_cur_state(cdev, state);
689+
if (result)
690+
return result;
691+
return count;
692+
}
693+
694+
static struct device_attribute dev_attr_cdev_type =
695+
__ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
696+
static DEVICE_ATTR(max_state, 0444,
697+
thermal_cooling_device_max_state_show, NULL);
698+
static DEVICE_ATTR(cur_state, 0644,
699+
thermal_cooling_device_cur_state_show,
700+
thermal_cooling_device_cur_state_store);
701+
702+
static struct attribute *cooling_device_attrs[] = {
703+
&dev_attr_cdev_type.attr,
704+
&dev_attr_max_state.attr,
705+
&dev_attr_cur_state.attr,
706+
NULL,
707+
};
708+
709+
static const struct attribute_group cooling_device_attr_group = {
710+
.attrs = cooling_device_attrs,
711+
};
712+
713+
static const struct attribute_group *cooling_device_attr_groups[] = {
714+
&cooling_device_attr_group,
715+
NULL,
716+
};
717+
718+
void thermal_cooling_device_setup_sysfs(struct thermal_cooling_device *cdev)
719+
{
720+
cdev->device.groups = cooling_device_attr_groups;
721+
}
722+
723+
/* these helper will be used only at the time of bindig */
724+
ssize_t
725+
thermal_cooling_device_trip_point_show(struct device *dev,
726+
struct device_attribute *attr, char *buf)
727+
{
728+
struct thermal_instance *instance;
729+
730+
instance =
731+
container_of(attr, struct thermal_instance, attr);
732+
733+
if (instance->trip == THERMAL_TRIPS_NONE)
734+
return sprintf(buf, "-1\n");
735+
else
736+
return sprintf(buf, "%d\n", instance->trip);
737+
}
738+
739+
ssize_t
740+
thermal_cooling_device_weight_show(struct device *dev,
741+
struct device_attribute *attr, char *buf)
742+
{
743+
struct thermal_instance *instance;
744+
745+
instance = container_of(attr, struct thermal_instance, weight_attr);
746+
747+
return sprintf(buf, "%d\n", instance->weight);
748+
}
749+
750+
ssize_t
751+
thermal_cooling_device_weight_store(struct device *dev,
752+
struct device_attribute *attr,
753+
const char *buf, size_t count)
754+
{
755+
struct thermal_instance *instance;
756+
int ret, weight;
757+
758+
ret = kstrtoint(buf, 0, &weight);
759+
if (ret)
760+
return ret;
761+
762+
instance = container_of(attr, struct thermal_instance, weight_attr);
763+
instance->weight = weight;
764+
765+
return count;
766+
}

0 commit comments

Comments
 (0)