89601f675b
Here is the big set of USB and Thunderbolt changes for 6.10-rc1. Nothing hugely earth-shattering, just constant forward progress for hardware support of new devices and cleanups over the drivers. Included in here are: - Thunderbolt / USB 4 driver updates - typec driver updates - dwc3 driver updates - gadget driver updates - uss720 driver id additions and fixes (people use USB->arallel port devices still!) - onboard-hub driver rename and additions for new hardware - xhci driver updates - other small USB driver updates and additions for quirks and api changes All of these have been in linux-next for a while with no reported problems. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> -----BEGIN PGP SIGNATURE----- iG0EABECAC0WIQT0tgzFv3jCIUoxPcsxR9QN2y37KQUCZk4E7w8cZ3JlZ0Brcm9h aC5jb20ACgkQMUfUDdst+yn0kACgr3uvAWXvfb9R4vCpC65F4f49ZQwAoIkHQBPl /5HdrlIIYW2OzdUixH3e =e3pI -----END PGP SIGNATURE----- Merge tag 'usb-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb Pull USB / Thunderbolt updates from Greg KH: "Here is the big set of USB and Thunderbolt changes for 6.10-rc1. Nothing hugely earth-shattering, just constant forward progress for hardware support of new devices and cleanups over the drivers. Included in here are: - Thunderbolt / USB 4 driver updates - typec driver updates - dwc3 driver updates - gadget driver updates - uss720 driver id additions and fixes (people use USB->arallel port devices still!) - onboard-hub driver rename and additions for new hardware - xhci driver updates - other small USB driver updates and additions for quirks and api changes All of these have been in linux-next for a while with no reported problems" * tag 'usb-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (154 commits) drm/bridge: aux-hpd-bridge: correct devm_drm_dp_hpd_bridge_add() stub usb: fotg210: Add missing kernel doc description usb: dwc3: core: Fix unused variable warning in core driver usb: typec: tipd: rely on i2c_get_match_data() usb: typec: tipd: fix event checking for tps6598x usb: typec: tipd: fix event checking for tps25750 dt-bindings: usb: qcom,dwc3: fix interrupt max items usb: fotg210: Use *-y instead of *-objs in Makefile usb: phy: tegra: Replace of_gpio.h by proper one usb: typec: ucsi: displayport: Fix potential deadlock usb: typec: qcom-pmic-typec: split HPD bridge alloc and registration usb: musc: Remove unused list 'buffers' usb: dwc3: Wait unconditionally after issuing EndXfer command usb: gadget: u_audio: Clear uac pointer when freed. usb: gadget: u_audio: Fix race condition use of controls after free during gadget unbind. dt-bindings: usb: dwc3: Add QDU1000 compatible usb: core: Remove the useless struct usb_devmap which is just a bitmap MAINTAINERS: Remove {ehci,uhci}-platform.c from ARM/VT8500 entry USB: usb_parse_endpoint: ignore reserved bits usb: xhci: compact 'trb_in_td()' arguments ...
388 lines
9.5 KiB
C
388 lines
9.5 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
|
|
* Copyright (c) 2022, Linaro Ltd
|
|
*/
|
|
#include <linux/auxiliary_bus.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/rpmsg.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/soc/qcom/pdr.h>
|
|
#include <linux/soc/qcom/pmic_glink.h>
|
|
#include <linux/spinlock.h>
|
|
|
|
enum {
|
|
PMIC_GLINK_CLIENT_BATT = 0,
|
|
PMIC_GLINK_CLIENT_ALTMODE,
|
|
PMIC_GLINK_CLIENT_UCSI,
|
|
};
|
|
|
|
struct pmic_glink {
|
|
struct device *dev;
|
|
struct pdr_handle *pdr;
|
|
|
|
struct rpmsg_endpoint *ept;
|
|
|
|
unsigned long client_mask;
|
|
|
|
struct auxiliary_device altmode_aux;
|
|
struct auxiliary_device ps_aux;
|
|
struct auxiliary_device ucsi_aux;
|
|
|
|
/* serializing client_state and pdr_state updates */
|
|
struct mutex state_lock;
|
|
unsigned int client_state;
|
|
unsigned int pdr_state;
|
|
|
|
/* serializing clients list updates */
|
|
spinlock_t client_lock;
|
|
struct list_head clients;
|
|
};
|
|
|
|
static struct pmic_glink *__pmic_glink;
|
|
static DEFINE_MUTEX(__pmic_glink_lock);
|
|
|
|
struct pmic_glink_client {
|
|
struct list_head node;
|
|
|
|
struct pmic_glink *pg;
|
|
unsigned int id;
|
|
|
|
void (*cb)(const void *data, size_t len, void *priv);
|
|
void (*pdr_notify)(void *priv, int state);
|
|
void *priv;
|
|
};
|
|
|
|
static void _devm_pmic_glink_release_client(struct device *dev, void *res)
|
|
{
|
|
struct pmic_glink_client *client = (struct pmic_glink_client *)res;
|
|
struct pmic_glink *pg = client->pg;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&pg->client_lock, flags);
|
|
list_del(&client->node);
|
|
spin_unlock_irqrestore(&pg->client_lock, flags);
|
|
}
|
|
|
|
struct pmic_glink_client *devm_pmic_glink_register_client(struct device *dev,
|
|
unsigned int id,
|
|
void (*cb)(const void *, size_t, void *),
|
|
void (*pdr)(void *, int),
|
|
void *priv)
|
|
{
|
|
struct pmic_glink_client *client;
|
|
struct pmic_glink *pg = dev_get_drvdata(dev->parent);
|
|
unsigned long flags;
|
|
|
|
client = devres_alloc(_devm_pmic_glink_release_client, sizeof(*client), GFP_KERNEL);
|
|
if (!client)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
client->pg = pg;
|
|
client->id = id;
|
|
client->cb = cb;
|
|
client->pdr_notify = pdr;
|
|
client->priv = priv;
|
|
|
|
mutex_lock(&pg->state_lock);
|
|
spin_lock_irqsave(&pg->client_lock, flags);
|
|
|
|
list_add(&client->node, &pg->clients);
|
|
client->pdr_notify(client->priv, pg->client_state);
|
|
|
|
spin_unlock_irqrestore(&pg->client_lock, flags);
|
|
mutex_unlock(&pg->state_lock);
|
|
|
|
devres_add(dev, client);
|
|
|
|
return client;
|
|
}
|
|
EXPORT_SYMBOL_GPL(devm_pmic_glink_register_client);
|
|
|
|
int pmic_glink_send(struct pmic_glink_client *client, void *data, size_t len)
|
|
{
|
|
struct pmic_glink *pg = client->pg;
|
|
|
|
return rpmsg_send(pg->ept, data, len);
|
|
}
|
|
EXPORT_SYMBOL_GPL(pmic_glink_send);
|
|
|
|
static int pmic_glink_rpmsg_callback(struct rpmsg_device *rpdev, void *data,
|
|
int len, void *priv, u32 addr)
|
|
{
|
|
struct pmic_glink_client *client;
|
|
struct pmic_glink_hdr *hdr;
|
|
struct pmic_glink *pg = dev_get_drvdata(&rpdev->dev);
|
|
unsigned long flags;
|
|
|
|
if (len < sizeof(*hdr)) {
|
|
dev_warn(pg->dev, "ignoring truncated message\n");
|
|
return 0;
|
|
}
|
|
|
|
hdr = data;
|
|
|
|
spin_lock_irqsave(&pg->client_lock, flags);
|
|
list_for_each_entry(client, &pg->clients, node) {
|
|
if (client->id == le32_to_cpu(hdr->owner))
|
|
client->cb(data, len, client->priv);
|
|
}
|
|
spin_unlock_irqrestore(&pg->client_lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pmic_glink_aux_release(struct device *dev) {}
|
|
|
|
static int pmic_glink_add_aux_device(struct pmic_glink *pg,
|
|
struct auxiliary_device *aux,
|
|
const char *name)
|
|
{
|
|
struct device *parent = pg->dev;
|
|
int ret;
|
|
|
|
aux->name = name;
|
|
aux->dev.parent = parent;
|
|
aux->dev.release = pmic_glink_aux_release;
|
|
device_set_of_node_from_dev(&aux->dev, parent);
|
|
ret = auxiliary_device_init(aux);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = auxiliary_device_add(aux);
|
|
if (ret)
|
|
auxiliary_device_uninit(aux);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void pmic_glink_del_aux_device(struct pmic_glink *pg,
|
|
struct auxiliary_device *aux)
|
|
{
|
|
auxiliary_device_delete(aux);
|
|
auxiliary_device_uninit(aux);
|
|
}
|
|
|
|
static void pmic_glink_state_notify_clients(struct pmic_glink *pg)
|
|
{
|
|
struct pmic_glink_client *client;
|
|
unsigned int new_state = pg->client_state;
|
|
unsigned long flags;
|
|
|
|
if (pg->client_state != SERVREG_SERVICE_STATE_UP) {
|
|
if (pg->pdr_state == SERVREG_SERVICE_STATE_UP && pg->ept)
|
|
new_state = SERVREG_SERVICE_STATE_UP;
|
|
} else {
|
|
if (pg->pdr_state == SERVREG_SERVICE_STATE_UP && pg->ept)
|
|
new_state = SERVREG_SERVICE_STATE_DOWN;
|
|
}
|
|
|
|
if (new_state != pg->client_state) {
|
|
spin_lock_irqsave(&pg->client_lock, flags);
|
|
list_for_each_entry(client, &pg->clients, node)
|
|
client->pdr_notify(client->priv, new_state);
|
|
spin_unlock_irqrestore(&pg->client_lock, flags);
|
|
pg->client_state = new_state;
|
|
}
|
|
}
|
|
|
|
static void pmic_glink_pdr_callback(int state, char *svc_path, void *priv)
|
|
{
|
|
struct pmic_glink *pg = priv;
|
|
|
|
mutex_lock(&pg->state_lock);
|
|
pg->pdr_state = state;
|
|
|
|
pmic_glink_state_notify_clients(pg);
|
|
mutex_unlock(&pg->state_lock);
|
|
}
|
|
|
|
static int pmic_glink_rpmsg_probe(struct rpmsg_device *rpdev)
|
|
{
|
|
struct pmic_glink *pg = __pmic_glink;
|
|
int ret = 0;
|
|
|
|
mutex_lock(&__pmic_glink_lock);
|
|
if (!pg) {
|
|
ret = dev_err_probe(&rpdev->dev, -ENODEV, "no pmic_glink device to attach to\n");
|
|
goto out_unlock;
|
|
}
|
|
|
|
dev_set_drvdata(&rpdev->dev, pg);
|
|
|
|
mutex_lock(&pg->state_lock);
|
|
pg->ept = rpdev->ept;
|
|
pmic_glink_state_notify_clients(pg);
|
|
mutex_unlock(&pg->state_lock);
|
|
|
|
out_unlock:
|
|
mutex_unlock(&__pmic_glink_lock);
|
|
return ret;
|
|
}
|
|
|
|
static void pmic_glink_rpmsg_remove(struct rpmsg_device *rpdev)
|
|
{
|
|
struct pmic_glink *pg;
|
|
|
|
mutex_lock(&__pmic_glink_lock);
|
|
pg = __pmic_glink;
|
|
if (!pg)
|
|
goto out_unlock;
|
|
|
|
mutex_lock(&pg->state_lock);
|
|
pg->ept = NULL;
|
|
pmic_glink_state_notify_clients(pg);
|
|
mutex_unlock(&pg->state_lock);
|
|
out_unlock:
|
|
mutex_unlock(&__pmic_glink_lock);
|
|
}
|
|
|
|
static const struct rpmsg_device_id pmic_glink_rpmsg_id_match[] = {
|
|
{ "PMIC_RTR_ADSP_APPS" },
|
|
{}
|
|
};
|
|
|
|
static struct rpmsg_driver pmic_glink_rpmsg_driver = {
|
|
.probe = pmic_glink_rpmsg_probe,
|
|
.remove = pmic_glink_rpmsg_remove,
|
|
.callback = pmic_glink_rpmsg_callback,
|
|
.id_table = pmic_glink_rpmsg_id_match,
|
|
.drv = {
|
|
.name = "qcom_pmic_glink_rpmsg",
|
|
},
|
|
};
|
|
|
|
static int pmic_glink_probe(struct platform_device *pdev)
|
|
{
|
|
const unsigned long *match_data;
|
|
struct pdr_service *service;
|
|
struct pmic_glink *pg;
|
|
int ret;
|
|
|
|
pg = devm_kzalloc(&pdev->dev, sizeof(*pg), GFP_KERNEL);
|
|
if (!pg)
|
|
return -ENOMEM;
|
|
|
|
dev_set_drvdata(&pdev->dev, pg);
|
|
|
|
pg->dev = &pdev->dev;
|
|
|
|
INIT_LIST_HEAD(&pg->clients);
|
|
spin_lock_init(&pg->client_lock);
|
|
mutex_init(&pg->state_lock);
|
|
|
|
match_data = (unsigned long *)of_device_get_match_data(&pdev->dev);
|
|
if (!match_data)
|
|
return -EINVAL;
|
|
|
|
pg->client_mask = *match_data;
|
|
|
|
pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
|
|
if (IS_ERR(pg->pdr)) {
|
|
ret = dev_err_probe(&pdev->dev, PTR_ERR(pg->pdr),
|
|
"failed to initialize pdr\n");
|
|
return ret;
|
|
}
|
|
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI)) {
|
|
ret = pmic_glink_add_aux_device(pg, &pg->ucsi_aux, "ucsi");
|
|
if (ret)
|
|
goto out_release_pdr_handle;
|
|
}
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE)) {
|
|
ret = pmic_glink_add_aux_device(pg, &pg->altmode_aux, "altmode");
|
|
if (ret)
|
|
goto out_release_ucsi_aux;
|
|
}
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT)) {
|
|
ret = pmic_glink_add_aux_device(pg, &pg->ps_aux, "power-supply");
|
|
if (ret)
|
|
goto out_release_altmode_aux;
|
|
}
|
|
|
|
service = pdr_add_lookup(pg->pdr, "tms/servreg", "msm/adsp/charger_pd");
|
|
if (IS_ERR(service)) {
|
|
ret = dev_err_probe(&pdev->dev, PTR_ERR(service),
|
|
"failed adding pdr lookup for charger_pd\n");
|
|
goto out_release_aux_devices;
|
|
}
|
|
|
|
mutex_lock(&__pmic_glink_lock);
|
|
__pmic_glink = pg;
|
|
mutex_unlock(&__pmic_glink_lock);
|
|
|
|
return 0;
|
|
|
|
out_release_aux_devices:
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT))
|
|
pmic_glink_del_aux_device(pg, &pg->ps_aux);
|
|
out_release_altmode_aux:
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE))
|
|
pmic_glink_del_aux_device(pg, &pg->altmode_aux);
|
|
out_release_ucsi_aux:
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI))
|
|
pmic_glink_del_aux_device(pg, &pg->ucsi_aux);
|
|
out_release_pdr_handle:
|
|
pdr_handle_release(pg->pdr);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void pmic_glink_remove(struct platform_device *pdev)
|
|
{
|
|
struct pmic_glink *pg = dev_get_drvdata(&pdev->dev);
|
|
|
|
pdr_handle_release(pg->pdr);
|
|
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT))
|
|
pmic_glink_del_aux_device(pg, &pg->ps_aux);
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE))
|
|
pmic_glink_del_aux_device(pg, &pg->altmode_aux);
|
|
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI))
|
|
pmic_glink_del_aux_device(pg, &pg->ucsi_aux);
|
|
|
|
mutex_lock(&__pmic_glink_lock);
|
|
__pmic_glink = NULL;
|
|
mutex_unlock(&__pmic_glink_lock);
|
|
}
|
|
|
|
static const unsigned long pmic_glink_sm8450_client_mask = BIT(PMIC_GLINK_CLIENT_BATT) |
|
|
BIT(PMIC_GLINK_CLIENT_ALTMODE) |
|
|
BIT(PMIC_GLINK_CLIENT_UCSI);
|
|
|
|
static const struct of_device_id pmic_glink_of_match[] = {
|
|
{ .compatible = "qcom,pmic-glink", .data = &pmic_glink_sm8450_client_mask },
|
|
{}
|
|
};
|
|
MODULE_DEVICE_TABLE(of, pmic_glink_of_match);
|
|
|
|
static struct platform_driver pmic_glink_driver = {
|
|
.probe = pmic_glink_probe,
|
|
.remove_new = pmic_glink_remove,
|
|
.driver = {
|
|
.name = "qcom_pmic_glink",
|
|
.of_match_table = pmic_glink_of_match,
|
|
},
|
|
};
|
|
|
|
static int pmic_glink_init(void)
|
|
{
|
|
platform_driver_register(&pmic_glink_driver);
|
|
register_rpmsg_driver(&pmic_glink_rpmsg_driver);
|
|
|
|
return 0;
|
|
}
|
|
module_init(pmic_glink_init);
|
|
|
|
static void pmic_glink_exit(void)
|
|
{
|
|
unregister_rpmsg_driver(&pmic_glink_rpmsg_driver);
|
|
platform_driver_unregister(&pmic_glink_driver);
|
|
}
|
|
module_exit(pmic_glink_exit);
|
|
|
|
MODULE_DESCRIPTION("Qualcomm PMIC GLINK driver");
|
|
MODULE_LICENSE("GPL");
|