Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Greybus CPort control protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2015 Google Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright 2015 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/greybus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) /* Highest control-protocol version supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define GB_CONTROL_VERSION_MAJOR	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #define GB_CONTROL_VERSION_MINOR	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static int gb_control_get_version(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct gb_interface *intf = control->connection->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct gb_control_version_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	struct gb_control_version_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	request.major = GB_CONTROL_VERSION_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	request.minor = GB_CONTROL_VERSION_MINOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 				GB_CONTROL_TYPE_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 				&request, sizeof(request), &response,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 				sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			"failed to get control-protocol version: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (response.major > request.major) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			"unsupported major control-protocol version (%u > %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 			response.major, request.major);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	control->protocol_major = response.major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	control->protocol_minor = response.minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	dev_dbg(&intf->dev, "%s - %u.%u\n", __func__, response.major,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		response.minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int gb_control_get_bundle_version(struct gb_control *control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 					 struct gb_bundle *bundle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	struct gb_interface *intf = control->connection->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	struct gb_control_bundle_version_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct gb_control_bundle_version_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	request.bundle_id = bundle->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				GB_CONTROL_TYPE_BUNDLE_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 				&request, sizeof(request),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				&response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			"failed to get bundle %u class version: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			bundle->id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	bundle->class_major = response.major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	bundle->class_minor = response.minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	dev_dbg(&intf->dev, "%s - %u: %u.%u\n", __func__, bundle->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		response.major, response.minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) int gb_control_get_bundle_versions(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct gb_interface *intf = control->connection->intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	struct gb_bundle *bundle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (!control->has_bundle_version)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	list_for_each_entry(bundle, &intf->bundles, links) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		ret = gb_control_get_bundle_version(control, bundle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) /* Get Manifest's size from the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int gb_control_get_manifest_size_operation(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct gb_control_get_manifest_size_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct gb_connection *connection = intf->control->connection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	ret = gb_operation_sync(connection, GB_CONTROL_TYPE_GET_MANIFEST_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				NULL, 0, &response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		dev_err(&connection->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			"failed to get manifest size: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return le16_to_cpu(response.size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* Reads Manifest from the interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int gb_control_get_manifest_operation(struct gb_interface *intf, void *manifest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				      size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct gb_connection *connection = intf->control->connection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return gb_operation_sync(connection, GB_CONTROL_TYPE_GET_MANIFEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				NULL, 0, manifest, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int gb_control_connected_operation(struct gb_control *control, u16 cport_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct gb_control_connected_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	request.cport_id = cpu_to_le16(cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return gb_operation_sync(control->connection, GB_CONTROL_TYPE_CONNECTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 				 &request, sizeof(request), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int gb_control_disconnected_operation(struct gb_control *control, u16 cport_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	struct gb_control_disconnected_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	request.cport_id = cpu_to_le16(cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	return gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				 GB_CONTROL_TYPE_DISCONNECTED, &request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				 sizeof(request), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) int gb_control_disconnecting_operation(struct gb_control *control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				       u16 cport_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct gb_control_disconnecting_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct gb_operation *operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	operation = gb_operation_create_core(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 					     GB_CONTROL_TYPE_DISCONNECTING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 					     sizeof(*request), 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 					     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (!operation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	request = operation->request->payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	request->cport_id = cpu_to_le16(cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	ret = gb_operation_request_send_sync(operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		dev_err(&control->dev, "failed to send disconnecting: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	gb_operation_put(operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int gb_control_mode_switch_operation(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct gb_operation *operation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	operation = gb_operation_create_core(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 					     GB_CONTROL_TYPE_MODE_SWITCH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 					     0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 					     GB_OPERATION_FLAG_UNIDIRECTIONAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 					     GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (!operation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	ret = gb_operation_request_send_sync(operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		dev_err(&control->dev, "failed to send mode switch: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	gb_operation_put(operation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int gb_control_bundle_pm_status_map(u8 status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	case GB_CONTROL_BUNDLE_PM_INVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	case GB_CONTROL_BUNDLE_PM_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	case GB_CONTROL_BUNDLE_PM_NA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return -ENOMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	case GB_CONTROL_BUNDLE_PM_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return -EREMOTEIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) int gb_control_bundle_suspend(struct gb_control *control, u8 bundle_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct gb_control_bundle_pm_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct gb_control_bundle_pm_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	request.bundle_id = bundle_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				GB_CONTROL_TYPE_BUNDLE_SUSPEND, &request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				sizeof(request), &response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		dev_err(&control->dev, "failed to send bundle %u suspend: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			bundle_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (response.status != GB_CONTROL_BUNDLE_PM_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		dev_err(&control->dev, "failed to suspend bundle %u: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			bundle_id, response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		return gb_control_bundle_pm_status_map(response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int gb_control_bundle_resume(struct gb_control *control, u8 bundle_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct gb_control_bundle_pm_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct gb_control_bundle_pm_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	request.bundle_id = bundle_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 				GB_CONTROL_TYPE_BUNDLE_RESUME, &request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				sizeof(request), &response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		dev_err(&control->dev, "failed to send bundle %u resume: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			bundle_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (response.status != GB_CONTROL_BUNDLE_PM_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		dev_err(&control->dev, "failed to resume bundle %u: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			bundle_id, response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return gb_control_bundle_pm_status_map(response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) int gb_control_bundle_deactivate(struct gb_control *control, u8 bundle_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct gb_control_bundle_pm_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct gb_control_bundle_pm_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	request.bundle_id = bundle_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				GB_CONTROL_TYPE_BUNDLE_DEACTIVATE, &request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				sizeof(request), &response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		dev_err(&control->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			"failed to send bundle %u deactivate: %d\n", bundle_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (response.status != GB_CONTROL_BUNDLE_PM_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		dev_err(&control->dev, "failed to deactivate bundle %u: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			bundle_id, response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return gb_control_bundle_pm_status_map(response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int gb_control_bundle_activate(struct gb_control *control, u8 bundle_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct gb_control_bundle_pm_request request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	struct gb_control_bundle_pm_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (!control->has_bundle_activate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	request.bundle_id = bundle_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 				GB_CONTROL_TYPE_BUNDLE_ACTIVATE, &request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 				sizeof(request), &response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		dev_err(&control->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			"failed to send bundle %u activate: %d\n", bundle_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (response.status != GB_CONTROL_BUNDLE_PM_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		dev_err(&control->dev, "failed to activate bundle %u: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 			bundle_id, response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return gb_control_bundle_pm_status_map(response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static int gb_control_interface_pm_status_map(u8 status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	case GB_CONTROL_INTF_PM_BUSY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	case GB_CONTROL_INTF_PM_NA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return -ENOMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		return -EREMOTEIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int gb_control_interface_suspend_prepare(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	struct gb_control_intf_pm_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 				GB_CONTROL_TYPE_INTF_SUSPEND_PREPARE, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				&response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		dev_err(&control->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			"failed to send interface suspend prepare: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (response.status != GB_CONTROL_INTF_PM_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		dev_err(&control->dev, "interface error while preparing suspend: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		return gb_control_interface_pm_status_map(response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int gb_control_interface_deactivate_prepare(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	struct gb_control_intf_pm_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 				GB_CONTROL_TYPE_INTF_DEACTIVATE_PREPARE, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 				0, &response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		dev_err(&control->dev, "failed to send interface deactivate prepare: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (response.status != GB_CONTROL_INTF_PM_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		dev_err(&control->dev, "interface error while preparing deactivate: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 			response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return gb_control_interface_pm_status_map(response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) int gb_control_interface_hibernate_abort(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	struct gb_control_intf_pm_response response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	ret = gb_operation_sync(control->connection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 				GB_CONTROL_TYPE_INTF_HIBERNATE_ABORT, NULL, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 				&response, sizeof(response));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		dev_err(&control->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			"failed to send interface aborting hibernate: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	if (response.status != GB_CONTROL_INTF_PM_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		dev_err(&control->dev, "interface error while aborting hibernate: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		return gb_control_interface_pm_status_map(response.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static ssize_t vendor_string_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 				  struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct gb_control *control = to_gb_control(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	return scnprintf(buf, PAGE_SIZE, "%s\n", control->vendor_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static DEVICE_ATTR_RO(vendor_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) static ssize_t product_string_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 				   struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	struct gb_control *control = to_gb_control(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	return scnprintf(buf, PAGE_SIZE, "%s\n", control->product_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static DEVICE_ATTR_RO(product_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static struct attribute *control_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	&dev_attr_vendor_string.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	&dev_attr_product_string.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ATTRIBUTE_GROUPS(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static void gb_control_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	struct gb_control *control = to_gb_control(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	gb_connection_destroy(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	kfree(control->vendor_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	kfree(control->product_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	kfree(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) struct device_type greybus_control_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	.name =		"greybus_control",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	.release =	gb_control_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct gb_control *gb_control_create(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct gb_connection *connection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct gb_control *control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	control = kzalloc(sizeof(*control), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (!control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	control->intf = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	connection = gb_connection_create_control(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	if (IS_ERR(connection)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			"failed to create control connection: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 			PTR_ERR(connection));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		kfree(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return ERR_CAST(connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	control->connection = connection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	control->dev.parent = &intf->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	control->dev.bus = &greybus_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	control->dev.type = &greybus_control_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	control->dev.groups = control_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	control->dev.dma_mask = intf->dev.dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	device_initialize(&control->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	dev_set_name(&control->dev, "%s.ctrl", dev_name(&intf->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	gb_connection_set_data(control->connection, control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	return control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int gb_control_enable(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	dev_dbg(&control->connection->intf->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	ret = gb_connection_enable_tx(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		dev_err(&control->connection->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 			"failed to enable control connection: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	ret = gb_control_get_version(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		goto err_disable_connection;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	if (control->protocol_major > 0 || control->protocol_minor > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		control->has_bundle_version = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	/* FIXME: use protocol version instead */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	if (!(control->intf->quirks & GB_INTERFACE_QUIRK_NO_BUNDLE_ACTIVATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		control->has_bundle_activate = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) err_disable_connection:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	gb_connection_disable(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) void gb_control_disable(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	dev_dbg(&control->connection->intf->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	if (control->intf->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		gb_connection_disable_forced(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		gb_connection_disable(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) int gb_control_suspend(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	gb_connection_disable(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) int gb_control_resume(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	ret = gb_connection_enable_tx(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		dev_err(&control->connection->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 			"failed to enable control connection: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int gb_control_add(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	ret = device_add(&control->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		dev_err(&control->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			"failed to register control device: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) void gb_control_del(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	if (device_is_registered(&control->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		device_del(&control->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct gb_control *gb_control_get(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	get_device(&control->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	return control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) void gb_control_put(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	put_device(&control->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) void gb_control_mode_switch_prepare(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	gb_connection_mode_switch_prepare(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) void gb_control_mode_switch_complete(struct gb_control *control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	gb_connection_mode_switch_complete(control->connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }