From 20b9954fd6345ecd241c135d87081b4e10b4febc Mon Sep 17 00:00:00 2001 From: Michal Koziel <79845977+mkemlogic@users.noreply.github.com> Date: Wed, 15 Mar 2023 07:06:44 +0100 Subject: [PATCH] otgcontrol: register device on module init (#344) The otgcontrol device has been disabled in DT since we have started using the pogo driver. However, we still need otgcontrol in production. We don't want the device to be enabled in DT not to cause any conflicts with the pogo device, even if the otgcontrol driver can be blacklisted, and only loaded on request. This patch allows to bring up the device when the driver is loaded and read its DT nodes as if it was enabled in DT in the first place. Signed-off-by: Michal Koziel --- arch/arm/boot/dts/zero-sugar.dts | 11 ++++- drivers/misc/rm-otgcontrol/otgcontrol_main.c | 48 ++++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/arch/arm/boot/dts/zero-sugar.dts b/arch/arm/boot/dts/zero-sugar.dts index 331128589b94..c598161f357a 100644 --- a/arch/arm/boot/dts/zero-sugar.dts +++ b/arch/arm/boot/dts/zero-sugar.dts @@ -168,10 +168,10 @@ otgcontrol: otgcontrol1 { pinctrl-names = "default", "one_wire_uart_tx", "one_wire_uart_rx", "sleep"; - pinctrl-0 = <&pinctrl_one_wire_gpio>; + pinctrl-0 = <&pinctrl_one_wire_otg_gpio>; pinctrl-1 = <&pinctrl_one_wire_uart6_tx>; pinctrl-2 = <&pinctrl_one_wire_uart6_rx>; - pinctrl-3 = <&pinctrl_one_wire_gpio>; + pinctrl-3 = <&pinctrl_one_wire_otg_gpio>; compatible = "rm-otgcontrol"; vbus-supply =<&max77818_fg>; one-wire-tty-name = "ttymxc5"; @@ -1031,6 +1031,13 @@ >; }; + pinctrl_one_wire_otg_gpio: one_wire_otg_gpio_grp { + fsl,pins = < + MX7D_PAD_EPDC_DATA08__GPIO2_IO8 0x00000004 + MX7D_PAD_EPDC_DATA09__GPIO2_IO9 0x00000004 + >; + }; + pinctrl_one_wire_gpio: one_wire_gpio_grp { fsl,pins = < MX7D_PAD_EPDC_DATA08__GPIO2_IO8 0x00000034 diff --git a/drivers/misc/rm-otgcontrol/otgcontrol_main.c b/drivers/misc/rm-otgcontrol/otgcontrol_main.c index fefc0022905e..8f15bc24286f 100644 --- a/drivers/misc/rm-otgcontrol/otgcontrol_main.c +++ b/drivers/misc/rm-otgcontrol/otgcontrol_main.c @@ -100,7 +100,7 @@ static int rm_otgcontrol_init(struct rm_otgcontrol_data *otgc_data) static int rm_otgcontrol_parse_dt(struct rm_otgcontrol_data *otgc_data) { struct device *dev = otgc_data->dev; - struct device_node *np = dev->of_node; + struct device_node *np; struct rm_otgcontrol_platform_data *pdata = otgc_data->pdata; const char *vbus_supply_name; int ret = 0; @@ -109,6 +109,16 @@ static int rm_otgcontrol_parse_dt(struct rm_otgcontrol_data *otgc_data) "%s: Enter\n", __func__); + np = of_find_node_by_name(NULL, "otgcontrol1"); + + if (!np) { + dev_err(otgc_data->dev, + "%s: Failed looking up node 'otgcontrol1'\n", + __func__); + return -EINVAL; + } + dev->of_node = np; + if (of_find_property(np, "vbus-supply", NULL)) { dev_dbg(otgc_data->dev, "%s: Found vbus-supply property, " @@ -366,7 +376,7 @@ static SIMPLE_DEV_PM_OPS(rm_otgcontrol_pm_ops, static struct platform_driver rm_otgcontrol_driver = { .driver = { - .name = "rm_otg_control", + .name = "rm-otgcontrol", .owner = THIS_MODULE, #ifdef CONFIG_PM .pm = &rm_otgcontrol_pm_ops, @@ -377,7 +387,39 @@ static struct platform_driver rm_otgcontrol_driver = { .remove = rm_otgcontrol_remove, }; -module_platform_driver(rm_otgcontrol_driver); +/* + * module_platform_driver(rm_otgcontrol_driver); + * we are not using module_platform_driver(rm_otgcontrol_driver) + * to be able to register the device within this driver + */ + +static struct platform_device *rm_otgcontrol_dev; + +static int __init rm_otgcontrol_driver_init(void) +{ + int ret; + + rm_otgcontrol_dev = platform_device_alloc("rm-otgcontrol", -1); + if (!rm_otgcontrol_dev) + return -ENOMEM; + + ret = platform_device_add(rm_otgcontrol_dev); + if (ret) { + pr_err("%s: Failed registering device\n", __func__); + platform_device_put(rm_otgcontrol_dev); + return -ENOMEM; + } + + return platform_driver_register(&rm_otgcontrol_driver); +} +module_init(rm_otgcontrol_driver_init); +static void __exit rm_otgcontrol_driver_exit(void) \ +{ + platform_driver_unregister(&(rm_otgcontrol_driver)); + platform_device_unregister(rm_otgcontrol_dev); +} +module_exit(rm_otgcontrol_driver_exit); + MODULE_LICENSE("GPL v2"); MODULE_DESCRIPTION("reMarkable OTG control driver, to enable authentication of "