Skip to content

Commit ff64277

Browse files
superna9999andersson
authored andcommitted
soc: qcom: pmic_glink: register ucsi aux device
Only register UCSI on know working devices, like on the SM8450 or SM8550 which requires UCSI to get USB mode switch events. Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> Signed-off-by: Bjorn Andersson <andersson@kernel.org> Link: https://lore.kernel.org/r/20230130-topic-sm8450-upstream-pmic-glink-v5-4-552f3b721f9e@linaro.org
1 parent 84a3341 commit ff64277

1 file changed

Lines changed: 54 additions & 11 deletions

File tree

drivers/soc/qcom/pmic_glink.c

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,31 @@
44
* Copyright (c) 2022, Linaro Ltd
55
*/
66
#include <linux/auxiliary_bus.h>
7+
#include <linux/of_device.h>
78
#include <linux/module.h>
89
#include <linux/platform_device.h>
910
#include <linux/rpmsg.h>
1011
#include <linux/slab.h>
1112
#include <linux/soc/qcom/pdr.h>
1213
#include <linux/soc/qcom/pmic_glink.h>
1314

15+
enum {
16+
PMIC_GLINK_CLIENT_BATT = 0,
17+
PMIC_GLINK_CLIENT_ALTMODE,
18+
PMIC_GLINK_CLIENT_UCSI,
19+
};
20+
21+
#define PMIC_GLINK_CLIENT_DEFAULT (BIT(PMIC_GLINK_CLIENT_BATT) | \
22+
BIT(PMIC_GLINK_CLIENT_ALTMODE))
23+
1424
struct pmic_glink {
1525
struct device *dev;
1626
struct pdr_handle *pdr;
1727

1828
struct rpmsg_endpoint *ept;
1929

30+
unsigned long client_mask;
31+
2032
struct auxiliary_device altmode_aux;
2133
struct auxiliary_device ps_aux;
2234
struct auxiliary_device ucsi_aux;
@@ -233,6 +245,7 @@ static struct rpmsg_driver pmic_glink_rpmsg_driver = {
233245

234246
static int pmic_glink_probe(struct platform_device *pdev)
235247
{
248+
const unsigned long *match_data;
236249
struct pdr_service *service;
237250
struct pmic_glink *pg;
238251
int ret;
@@ -249,12 +262,27 @@ static int pmic_glink_probe(struct platform_device *pdev)
249262
mutex_init(&pg->client_lock);
250263
mutex_init(&pg->state_lock);
251264

252-
ret = pmic_glink_add_aux_device(pg, &pg->altmode_aux, "altmode");
253-
if (ret)
254-
return ret;
255-
ret = pmic_glink_add_aux_device(pg, &pg->ps_aux, "power-supply");
256-
if (ret)
257-
goto out_release_altmode_aux;
265+
match_data = (unsigned long *)of_device_get_match_data(&pdev->dev);
266+
if (match_data)
267+
pg->client_mask = *match_data;
268+
else
269+
pg->client_mask = PMIC_GLINK_CLIENT_DEFAULT;
270+
271+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI)) {
272+
ret = pmic_glink_add_aux_device(pg, &pg->ucsi_aux, "ucsi");
273+
if (ret)
274+
return ret;
275+
}
276+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE)) {
277+
ret = pmic_glink_add_aux_device(pg, &pg->altmode_aux, "altmode");
278+
if (ret)
279+
goto out_release_ucsi_aux;
280+
}
281+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT)) {
282+
ret = pmic_glink_add_aux_device(pg, &pg->ps_aux, "power-supply");
283+
if (ret)
284+
goto out_release_altmode_aux;
285+
}
258286

259287
pg->pdr = pdr_handle_alloc(pmic_glink_pdr_callback, pg);
260288
if (IS_ERR(pg->pdr)) {
@@ -278,9 +306,14 @@ static int pmic_glink_probe(struct platform_device *pdev)
278306
out_release_pdr_handle:
279307
pdr_handle_release(pg->pdr);
280308
out_release_aux_devices:
281-
pmic_glink_del_aux_device(pg, &pg->ps_aux);
309+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT))
310+
pmic_glink_del_aux_device(pg, &pg->ps_aux);
282311
out_release_altmode_aux:
283-
pmic_glink_del_aux_device(pg, &pg->altmode_aux);
312+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE))
313+
pmic_glink_del_aux_device(pg, &pg->altmode_aux);
314+
out_release_ucsi_aux:
315+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI))
316+
pmic_glink_del_aux_device(pg, &pg->ucsi_aux);
284317

285318
return ret;
286319
}
@@ -291,8 +324,12 @@ static int pmic_glink_remove(struct platform_device *pdev)
291324

292325
pdr_handle_release(pg->pdr);
293326

294-
pmic_glink_del_aux_device(pg, &pg->ps_aux);
295-
pmic_glink_del_aux_device(pg, &pg->altmode_aux);
327+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_BATT))
328+
pmic_glink_del_aux_device(pg, &pg->ps_aux);
329+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_ALTMODE))
330+
pmic_glink_del_aux_device(pg, &pg->altmode_aux);
331+
if (pg->client_mask & BIT(PMIC_GLINK_CLIENT_UCSI))
332+
pmic_glink_del_aux_device(pg, &pg->ucsi_aux);
296333

297334
mutex_lock(&__pmic_glink_lock);
298335
__pmic_glink = NULL;
@@ -301,8 +338,14 @@ static int pmic_glink_remove(struct platform_device *pdev)
301338
return 0;
302339
}
303340

341+
/* Do not handle altmode for now on those platforms */
342+
static const unsigned long pmic_glink_sm8450_client_mask = BIT(PMIC_GLINK_CLIENT_BATT) |
343+
BIT(PMIC_GLINK_CLIENT_UCSI);
344+
304345
static const struct of_device_id pmic_glink_of_match[] = {
305-
{ .compatible = "qcom,pmic-glink", },
346+
{ .compatible = "qcom,sm8450-pmic-glink", .data = &pmic_glink_sm8450_client_mask },
347+
{ .compatible = "qcom,sm8550-pmic-glink", .data = &pmic_glink_sm8450_client_mask },
348+
{ .compatible = "qcom,pmic-glink" },
306349
{}
307350
};
308351
MODULE_DEVICE_TABLE(of, pmic_glink_of_match);

0 commit comments

Comments
 (0)