Skip to content

Commit

Permalink
otgcontrol: register device on module init (#344)
Browse files Browse the repository at this point in the history
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 <michal.koziel@emlogic.no>
  • Loading branch information
mkemlogic committed Mar 15, 2023
1 parent 3d1b013 commit 20b9954
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
11 changes: 9 additions & 2 deletions arch/arm/boot/dts/zero-sugar.dts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
48 changes: 45 additions & 3 deletions drivers/misc/rm-otgcontrol/otgcontrol_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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, "
Expand Down Expand Up @@ -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,
Expand All @@ -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 "
Expand Down

0 comments on commit 20b9954

Please sign in to comment.