^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 interface code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2014 Google Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2014 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/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/greybus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "greybus_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define GB_INTERFACE_MODE_SWITCH_TIMEOUT 2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define GB_INTERFACE_DEVICE_ID_BAD 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define GB_INTERFACE_AUTOSUSPEND_MS 3000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* Time required for interface to enter standby before disabling REFCLK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define GB_INTERFACE_SUSPEND_HIBERNATE_DELAY_MS 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* Don't-care selector index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define DME_SELECTOR_INDEX_NULL 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* DME attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* FIXME: remove ES2 support and DME_T_TST_SRC_INCREMENT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define DME_T_TST_SRC_INCREMENT 0x4083
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define DME_DDBL1_MANUFACTURERID 0x5003
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define DME_DDBL1_PRODUCTID 0x5004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DME_TOSHIBA_GMP_VID 0x6000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define DME_TOSHIBA_GMP_PID 0x6001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define DME_TOSHIBA_GMP_SN0 0x6002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define DME_TOSHIBA_GMP_SN1 0x6003
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define DME_TOSHIBA_GMP_INIT_STATUS 0x6101
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /* DDBL1 Manufacturer and Product ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define TOSHIBA_DMID 0x0126
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define TOSHIBA_ES2_BRIDGE_DPID 0x1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define TOSHIBA_ES3_APBRIDGE_DPID 0x1001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define TOSHIBA_ES3_GBPHY_DPID 0x1002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static int gb_interface_hibernate_link(struct gb_interface *intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static int gb_interface_refclk_set(struct gb_interface *intf, bool enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int gb_interface_dme_attr_get(struct gb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u16 attr, u32 *val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return gb_svc_dme_peer_get(intf->hd->svc, intf->interface_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) attr, DME_SELECTOR_INDEX_NULL, val);
^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_interface_read_ara_dme(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u32 sn0, sn1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Unless this is a Toshiba bridge, bail out until we have defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * standard GMP attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (intf->ddbl1_manufacturer_id != TOSHIBA_DMID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) dev_err(&intf->dev, "unknown manufacturer %08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) intf->ddbl1_manufacturer_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ret = gb_interface_dme_attr_get(intf, DME_TOSHIBA_GMP_VID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) &intf->vendor_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (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) ret = gb_interface_dme_attr_get(intf, DME_TOSHIBA_GMP_PID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) &intf->product_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ret = gb_interface_dme_attr_get(intf, DME_TOSHIBA_GMP_SN0, &sn0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ret = gb_interface_dme_attr_get(intf, DME_TOSHIBA_GMP_SN1, &sn1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) intf->serial_number = (u64)sn1 << 32 | sn0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int gb_interface_read_dme(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* DME attributes have already been read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (intf->dme_read)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) ret = gb_interface_dme_attr_get(intf, DME_DDBL1_MANUFACTURERID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) &intf->ddbl1_manufacturer_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) ret = gb_interface_dme_attr_get(intf, DME_DDBL1_PRODUCTID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) &intf->ddbl1_product_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (intf->ddbl1_manufacturer_id == TOSHIBA_DMID &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) intf->ddbl1_product_id == TOSHIBA_ES2_BRIDGE_DPID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) intf->quirks |= GB_INTERFACE_QUIRK_NO_GMP_IDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) intf->quirks |= GB_INTERFACE_QUIRK_NO_INIT_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ret = gb_interface_read_ara_dme(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) intf->dme_read = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int gb_interface_route_create(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u8 intf_id = intf->interface_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u8 device_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Allocate an interface device id. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) ret = ida_simple_get(&svc->device_id_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) GB_SVC_DEVICE_ID_MIN, GB_SVC_DEVICE_ID_MAX + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) dev_err(&intf->dev, "failed to allocate device id: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) device_id = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ret = gb_svc_intf_device_id(svc, intf_id, device_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) dev_err(&intf->dev, "failed to set device id %u: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) device_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) goto err_ida_remove;
^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) /* FIXME: Hard-coded AP device id. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ret = gb_svc_route_create(svc, svc->ap_intf_id, GB_SVC_DEVICE_ID_AP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) intf_id, device_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) dev_err(&intf->dev, "failed to create route: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto err_svc_id_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) intf->device_id = device_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) err_svc_id_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * XXX Should we tell SVC that this id doesn't belong to interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * XXX anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) err_ida_remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) ida_simple_remove(&svc->device_id_map, device_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return 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) static void gb_interface_route_destroy(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (intf->device_id == GB_INTERFACE_DEVICE_ID_BAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) gb_svc_route_destroy(svc, svc->ap_intf_id, intf->interface_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) ida_simple_remove(&svc->device_id_map, intf->device_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) intf->device_id = GB_INTERFACE_DEVICE_ID_BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* Locking: Caller holds the interface mutex. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int gb_interface_legacy_mode_switch(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) dev_info(&intf->dev, "legacy mode switch detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Mark as disconnected to prevent I/O during disable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) intf->disconnected = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) gb_interface_disable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) intf->disconnected = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ret = gb_interface_enable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dev_err(&intf->dev, "failed to re-enable interface: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void gb_interface_mailbox_event(struct gb_interface *intf, u16 result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) u32 mailbox)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) mutex_lock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) dev_warn(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) "mailbox event with UniPro error: 0x%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto err_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (mailbox != GB_SVC_INTF_MAILBOX_GREYBUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) dev_warn(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) "mailbox event with unexpected value: 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) mailbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto err_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (intf->quirks & GB_INTERFACE_QUIRK_LEGACY_MODE_SWITCH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) gb_interface_legacy_mode_switch(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!intf->mode_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) dev_warn(&intf->dev, "unexpected mailbox event: 0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) mailbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) goto err_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) dev_info(&intf->dev, "mode switch detected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) complete(&intf->mode_switch_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) err_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) gb_interface_disable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static void gb_interface_mode_switch_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct gb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct gb_control *control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) intf = container_of(work, struct gb_interface, mode_switch_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) mutex_lock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* Make sure interface is still enabled. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (!intf->enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) dev_dbg(&intf->dev, "mode switch aborted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) intf->mode_switch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) goto out_interface_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * Prepare the control device for mode switch and make sure to get an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * extra reference before it goes away during interface disable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) control = gb_control_get(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) gb_control_mode_switch_prepare(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) gb_interface_disable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) timeout = msecs_to_jiffies(GB_INTERFACE_MODE_SWITCH_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ret = wait_for_completion_interruptible_timeout(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) &intf->mode_switch_completion, timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* Finalise control-connection mode switch. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) gb_control_mode_switch_complete(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) gb_control_put(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) dev_err(&intf->dev, "mode switch interrupted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) goto err_deactivate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) } else if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) dev_err(&intf->dev, "mode switch timed out\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) goto err_deactivate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* Re-enable (re-enumerate) interface if still active. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) mutex_lock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) intf->mode_switch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (intf->active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) ret = gb_interface_enable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) dev_err(&intf->dev, "failed to re-enable interface: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) out_interface_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) gb_interface_put(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) err_deactivate:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) mutex_lock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) intf->mode_switch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) gb_interface_put(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) int gb_interface_request_mode_switch(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) mutex_lock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (intf->mode_switch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) goto out_unlock;
^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) intf->mode_switch = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) reinit_completion(&intf->mode_switch_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * Get a reference to the interface device, which will be put once the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * mode switch is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) get_device(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (!queue_work(system_long_wq, &intf->mode_switch_work)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) put_device(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) goto out_unlock;
^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) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) EXPORT_SYMBOL_GPL(gb_interface_request_mode_switch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * T_TstSrcIncrement is written by the module on ES2 as a stand-in for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * init-status attribute DME_TOSHIBA_INIT_STATUS. The AP needs to read and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * clear it after reading a non-zero value from it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * FIXME: This is module-hardware dependent and needs to be extended for every
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * type of module we want to support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int gb_interface_read_and_clear_init_status(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct gb_host_device *hd = intf->hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) unsigned long bootrom_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) unsigned long s2l_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) u32 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) u16 attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) u8 init_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * ES2 bridges use T_TstSrcIncrement for the init status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * FIXME: Remove ES2 support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (intf->quirks & GB_INTERFACE_QUIRK_NO_INIT_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) attr = DME_T_TST_SRC_INCREMENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) attr = DME_TOSHIBA_GMP_INIT_STATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ret = gb_svc_dme_peer_get(hd->svc, intf->interface_id, attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) DME_SELECTOR_INDEX_NULL, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * A nonzero init status indicates the module has finished
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * initializing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (!value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) dev_err(&intf->dev, "invalid init status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * Extract the init status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * For ES2: We need to check lowest 8 bits of 'value'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * For ES3: We need to check highest 8 bits out of 32 of 'value'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * FIXME: Remove ES2 support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (intf->quirks & GB_INTERFACE_QUIRK_NO_INIT_STATUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) init_status = value & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) init_status = value >> 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * Check if the interface is executing the quirky ES3 bootrom that,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * for example, requires E2EFC, CSD and CSV to be disabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) bootrom_quirks = GB_INTERFACE_QUIRK_NO_CPORT_FEATURES |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) GB_INTERFACE_QUIRK_FORCED_DISABLE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) GB_INTERFACE_QUIRK_LEGACY_MODE_SWITCH |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) GB_INTERFACE_QUIRK_NO_BUNDLE_ACTIVATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) s2l_quirks = GB_INTERFACE_QUIRK_NO_PM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) switch (init_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) case GB_INIT_BOOTROM_UNIPRO_BOOT_STARTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) case GB_INIT_BOOTROM_FALLBACK_UNIPRO_BOOT_STARTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) intf->quirks |= bootrom_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) case GB_INIT_S2_LOADER_BOOT_STARTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) /* S2 Loader doesn't support runtime PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) intf->quirks &= ~bootrom_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) intf->quirks |= s2l_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) intf->quirks &= ~bootrom_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) intf->quirks &= ~s2l_quirks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /* Clear the init status. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return gb_svc_dme_peer_set(hd->svc, intf->interface_id, attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) DME_SELECTOR_INDEX_NULL, 0);
^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) /* interface sysfs attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #define gb_interface_attr(field, type) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static ssize_t field##_show(struct device *dev, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct device_attribute *attr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) struct gb_interface *intf = to_gb_interface(dev); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return scnprintf(buf, PAGE_SIZE, type"\n", intf->field); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static DEVICE_ATTR_RO(field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) gb_interface_attr(ddbl1_manufacturer_id, "0x%08x");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) gb_interface_attr(ddbl1_product_id, "0x%08x");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) gb_interface_attr(interface_id, "%u");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) gb_interface_attr(vendor_id, "0x%08x");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) gb_interface_attr(product_id, "0x%08x");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) gb_interface_attr(serial_number, "0x%016llx");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) static ssize_t voltage_now_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) u32 measurement;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ret = gb_svc_pwrmon_intf_sample_get(intf->hd->svc, intf->interface_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) GB_SVC_PWRMON_TYPE_VOL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) &measurement);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) dev_err(&intf->dev, "failed to get voltage sample (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) return sprintf(buf, "%u\n", measurement);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static DEVICE_ATTR_RO(voltage_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static ssize_t current_now_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) u32 measurement;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) ret = gb_svc_pwrmon_intf_sample_get(intf->hd->svc, intf->interface_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) GB_SVC_PWRMON_TYPE_CURR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) &measurement);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) dev_err(&intf->dev, "failed to get current sample (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return sprintf(buf, "%u\n", measurement);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) static DEVICE_ATTR_RO(current_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static ssize_t power_now_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) u32 measurement;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ret = gb_svc_pwrmon_intf_sample_get(intf->hd->svc, intf->interface_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) GB_SVC_PWRMON_TYPE_PWR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) &measurement);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) dev_err(&intf->dev, "failed to get power sample (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return sprintf(buf, "%u\n", measurement);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) static DEVICE_ATTR_RO(power_now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) static ssize_t power_state_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (intf->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return scnprintf(buf, PAGE_SIZE, "on\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return scnprintf(buf, PAGE_SIZE, "off\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static ssize_t power_state_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct device_attribute *attr, const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) bool activate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (kstrtobool(buf, &activate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) mutex_lock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (activate == intf->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (activate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) ret = gb_interface_activate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) "failed to activate interface: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) ret = gb_interface_enable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) dev_err(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) "failed to enable interface: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) gb_interface_disable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) mutex_unlock(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static DEVICE_ATTR_RW(power_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) static const char *gb_interface_type_string(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static const char * const types[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) [GB_INTERFACE_TYPE_INVALID] = "invalid",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) [GB_INTERFACE_TYPE_UNKNOWN] = "unknown",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) [GB_INTERFACE_TYPE_DUMMY] = "dummy",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) [GB_INTERFACE_TYPE_UNIPRO] = "unipro",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) [GB_INTERFACE_TYPE_GREYBUS] = "greybus",
^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) return types[intf->type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) static ssize_t interface_type_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return sprintf(buf, "%s\n", gb_interface_type_string(intf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static DEVICE_ATTR_RO(interface_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static struct attribute *interface_unipro_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) &dev_attr_ddbl1_manufacturer_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) &dev_attr_ddbl1_product_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static struct attribute *interface_greybus_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) &dev_attr_vendor_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) &dev_attr_product_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) &dev_attr_serial_number.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static struct attribute *interface_power_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) &dev_attr_voltage_now.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) &dev_attr_current_now.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) &dev_attr_power_now.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) &dev_attr_power_state.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) static struct attribute *interface_common_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) &dev_attr_interface_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) &dev_attr_interface_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) static umode_t interface_unipro_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct attribute *attr, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) struct device *dev = kobj_to_dev(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) switch (intf->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) case GB_INTERFACE_TYPE_UNIPRO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) case GB_INTERFACE_TYPE_GREYBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return attr->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) static umode_t interface_greybus_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct attribute *attr, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct device *dev = kobj_to_dev(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) switch (intf->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) case GB_INTERFACE_TYPE_GREYBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) return attr->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) static umode_t interface_power_is_visible(struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) struct attribute *attr, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) struct device *dev = kobj_to_dev(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) switch (intf->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) case GB_INTERFACE_TYPE_UNIPRO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) case GB_INTERFACE_TYPE_GREYBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) return attr->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) static const struct attribute_group interface_unipro_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) .is_visible = interface_unipro_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) .attrs = interface_unipro_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static const struct attribute_group interface_greybus_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) .is_visible = interface_greybus_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) .attrs = interface_greybus_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static const struct attribute_group interface_power_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) .is_visible = interface_power_is_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .attrs = interface_power_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) static const struct attribute_group interface_common_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) .attrs = interface_common_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static const struct attribute_group *interface_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) &interface_unipro_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) &interface_greybus_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) &interface_power_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) &interface_common_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) static void gb_interface_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) trace_gb_interface_release(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) kfree(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) static int gb_interface_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) ret = gb_control_interface_suspend_prepare(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) ret = gb_control_suspend(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) goto err_hibernate_abort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) ret = gb_interface_hibernate_link(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) /* Delay to allow interface to enter standby before disabling refclk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) msleep(GB_INTERFACE_SUSPEND_HIBERNATE_DELAY_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) ret = gb_interface_refclk_set(intf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) err_hibernate_abort:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) gb_control_interface_hibernate_abort(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) static int gb_interface_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) struct gb_interface *intf = to_gb_interface(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) ret = gb_interface_refclk_set(intf, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) ret = gb_svc_intf_resume(svc, intf->interface_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) ret = gb_control_resume(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static int gb_interface_runtime_idle(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) pm_runtime_mark_last_busy(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) pm_request_autosuspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) static const struct dev_pm_ops gb_interface_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) SET_RUNTIME_PM_OPS(gb_interface_suspend, gb_interface_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) gb_interface_runtime_idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) struct device_type greybus_interface_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) .name = "greybus_interface",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) .release = gb_interface_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) .pm = &gb_interface_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) * A Greybus module represents a user-replaceable component on a GMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) * phone. An interface is the physical connection on that module. A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) * module may have more than one interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * Create a gb_interface structure to represent a discovered interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) * The position of interface within the Endo is encoded in "interface_id"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * argument.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) * Returns a pointer to the new interfce or a null pointer if a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) * failure occurs due to memory exhaustion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) struct gb_interface *gb_interface_create(struct gb_module *module,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) u8 interface_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct gb_host_device *hd = module->hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) struct gb_interface *intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) intf = kzalloc(sizeof(*intf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) if (!intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) intf->hd = hd; /* XXX refcount? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) intf->module = module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) intf->interface_id = interface_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) INIT_LIST_HEAD(&intf->bundles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) INIT_LIST_HEAD(&intf->manifest_descs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) mutex_init(&intf->mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) INIT_WORK(&intf->mode_switch_work, gb_interface_mode_switch_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) init_completion(&intf->mode_switch_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) /* Invalid device id to start with */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) intf->device_id = GB_INTERFACE_DEVICE_ID_BAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) intf->dev.parent = &module->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) intf->dev.bus = &greybus_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) intf->dev.type = &greybus_interface_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) intf->dev.groups = interface_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) intf->dev.dma_mask = module->dev.dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) device_initialize(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) dev_set_name(&intf->dev, "%s.%u", dev_name(&module->dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) interface_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) pm_runtime_set_autosuspend_delay(&intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) GB_INTERFACE_AUTOSUSPEND_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) trace_gb_interface_create(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) return intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) static int gb_interface_vsys_set(struct gb_interface *intf, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) dev_dbg(&intf->dev, "%s - %d\n", __func__, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) ret = gb_svc_intf_vsys_set(svc, intf->interface_id, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) dev_err(&intf->dev, "failed to set v_sys: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) static int gb_interface_refclk_set(struct gb_interface *intf, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) dev_dbg(&intf->dev, "%s - %d\n", __func__, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) ret = gb_svc_intf_refclk_set(svc, intf->interface_id, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) dev_err(&intf->dev, "failed to set refclk: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) static int gb_interface_unipro_set(struct gb_interface *intf, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) dev_dbg(&intf->dev, "%s - %d\n", __func__, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) ret = gb_svc_intf_unipro_set(svc, intf->interface_id, enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) dev_err(&intf->dev, "failed to set UniPro: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) static int gb_interface_activate_operation(struct gb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) enum gb_interface_type *intf_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) dev_dbg(&intf->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) ret = gb_svc_intf_activate(svc, intf->interface_id, &type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) dev_err(&intf->dev, "failed to activate: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) switch (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) case GB_SVC_INTF_TYPE_DUMMY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) *intf_type = GB_INTERFACE_TYPE_DUMMY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) /* FIXME: handle as an error for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) case GB_SVC_INTF_TYPE_UNIPRO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) *intf_type = GB_INTERFACE_TYPE_UNIPRO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) dev_err(&intf->dev, "interface type UniPro not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) /* FIXME: handle as an error for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) case GB_SVC_INTF_TYPE_GREYBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) *intf_type = GB_INTERFACE_TYPE_GREYBUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) dev_err(&intf->dev, "unknown interface type: %u\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) *intf_type = GB_INTERFACE_TYPE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) static int gb_interface_hibernate_link(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) struct gb_svc *svc = intf->hd->svc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) return gb_svc_intf_set_power_mode_hibernate(svc, intf->interface_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) static int _gb_interface_activate(struct gb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) enum gb_interface_type *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) *type = GB_INTERFACE_TYPE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) if (intf->ejected || intf->removed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) ret = gb_interface_vsys_set(intf, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) ret = gb_interface_refclk_set(intf, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) goto err_vsys_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) ret = gb_interface_unipro_set(intf, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) goto err_refclk_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) ret = gb_interface_activate_operation(intf, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) switch (*type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) case GB_INTERFACE_TYPE_UNIPRO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) case GB_INTERFACE_TYPE_GREYBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) goto err_hibernate_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) goto err_unipro_disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) ret = gb_interface_read_dme(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) goto err_hibernate_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) ret = gb_interface_route_create(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) goto err_hibernate_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) intf->active = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) trace_gb_interface_activate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) err_hibernate_link:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) gb_interface_hibernate_link(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) err_unipro_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) gb_interface_unipro_set(intf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) err_refclk_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) gb_interface_refclk_set(intf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) err_vsys_disable:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) gb_interface_vsys_set(intf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) * At present, we assume a UniPro-only module to be a Greybus module that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) * failed to send its mailbox poke. There is some reason to believe that this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * is because of a bug in the ES3 bootrom.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) * FIXME: Check if this is a Toshiba bridge before retrying?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) static int _gb_interface_activate_es3_hack(struct gb_interface *intf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) enum gb_interface_type *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) int retries = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) while (retries--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) ret = _gb_interface_activate(intf, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) if (ret == -ENODEV && *type == GB_INTERFACE_TYPE_UNIPRO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) * Activate an interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * Locking: Caller holds the interface mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) int gb_interface_activate(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) enum gb_interface_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) switch (intf->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) case GB_INTERFACE_TYPE_INVALID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) case GB_INTERFACE_TYPE_GREYBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) ret = _gb_interface_activate_es3_hack(intf, &type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) ret = _gb_interface_activate(intf, &type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) /* Make sure type is detected correctly during reactivation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) if (intf->type != GB_INTERFACE_TYPE_INVALID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) if (type != intf->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) dev_err(&intf->dev, "failed to detect interface type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) intf->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) * Deactivate an interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * Locking: Caller holds the interface mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) void gb_interface_deactivate(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) if (!intf->active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) trace_gb_interface_deactivate(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) /* Abort any ongoing mode switch. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (intf->mode_switch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) complete(&intf->mode_switch_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) gb_interface_route_destroy(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) gb_interface_hibernate_link(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) gb_interface_unipro_set(intf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) gb_interface_refclk_set(intf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) gb_interface_vsys_set(intf, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) intf->active = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * Enable an interface by enabling its control connection, fetching the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) * manifest and other information over it, and finally registering its child
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) * devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) * Locking: Caller holds the interface mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) int gb_interface_enable(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) struct gb_control *control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) struct gb_bundle *bundle, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) int ret, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) void *manifest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) ret = gb_interface_read_and_clear_init_status(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) dev_err(&intf->dev, "failed to clear init status: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) /* Establish control connection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) control = gb_control_create(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (IS_ERR(control)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) dev_err(&intf->dev, "failed to create control device: %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) PTR_ERR(control));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) return PTR_ERR(control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) intf->control = control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) ret = gb_control_enable(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) goto err_put_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /* Get manifest size using control protocol on CPort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) size = gb_control_get_manifest_size_operation(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) if (size <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) dev_err(&intf->dev, "failed to get manifest size: %d\n", size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) ret = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) goto err_disable_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) manifest = kmalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) if (!manifest) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) goto err_disable_control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) /* Get manifest using control protocol on CPort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) ret = gb_control_get_manifest_operation(intf, manifest, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) dev_err(&intf->dev, "failed to get manifest: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) goto err_free_manifest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) * Parse the manifest and build up our data structures representing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) * what's in it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) if (!gb_manifest_parse(intf, manifest, size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) dev_err(&intf->dev, "failed to parse manifest\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) goto err_destroy_bundles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) ret = gb_control_get_bundle_versions(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) goto err_destroy_bundles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) /* Register the control device and any bundles */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) ret = gb_control_add(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) goto err_destroy_bundles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) pm_runtime_use_autosuspend(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) pm_runtime_get_noresume(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) pm_runtime_set_active(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) pm_runtime_enable(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) list_for_each_entry_safe_reverse(bundle, tmp, &intf->bundles, links) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) ret = gb_bundle_add(bundle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) gb_bundle_destroy(bundle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) kfree(manifest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) intf->enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) pm_runtime_put(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) trace_gb_interface_enable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) err_destroy_bundles:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) list_for_each_entry_safe(bundle, tmp, &intf->bundles, links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) gb_bundle_destroy(bundle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) err_free_manifest:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) kfree(manifest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) err_disable_control:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) gb_control_disable(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) err_put_control:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) gb_control_put(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) intf->control = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) * Disable an interface and destroy its bundles.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) * Locking: Caller holds the interface mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) void gb_interface_disable(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) struct gb_bundle *bundle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) struct gb_bundle *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) if (!intf->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) trace_gb_interface_disable(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) pm_runtime_get_sync(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) /* Set disconnected flag to avoid I/O during connection tear down. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) if (intf->quirks & GB_INTERFACE_QUIRK_FORCED_DISABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) intf->disconnected = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) list_for_each_entry_safe(bundle, next, &intf->bundles, links)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) gb_bundle_destroy(bundle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) if (!intf->mode_switch && !intf->disconnected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) gb_control_interface_deactivate_prepare(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) gb_control_del(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) gb_control_disable(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) gb_control_put(intf->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) intf->control = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) intf->enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) pm_runtime_disable(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) pm_runtime_set_suspended(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) pm_runtime_dont_use_autosuspend(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) pm_runtime_put_noidle(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) /* Register an interface. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) int gb_interface_add(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) ret = device_add(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) dev_err(&intf->dev, "failed to register interface: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) trace_gb_interface_add(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) dev_info(&intf->dev, "Interface added (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) gb_interface_type_string(intf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) switch (intf->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) case GB_INTERFACE_TYPE_GREYBUS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) dev_info(&intf->dev, "GMP VID=0x%08x, PID=0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) intf->vendor_id, intf->product_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) case GB_INTERFACE_TYPE_UNIPRO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) dev_info(&intf->dev, "DDBL1 Manufacturer=0x%08x, Product=0x%08x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) intf->ddbl1_manufacturer_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) intf->ddbl1_product_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) /* Deregister an interface. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) void gb_interface_del(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) if (device_is_registered(&intf->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) trace_gb_interface_del(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) device_del(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) dev_info(&intf->dev, "Interface removed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) void gb_interface_put(struct gb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) put_device(&intf->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }