otgcontrol: adjust to 8 char tab width and squeeze code within 80 chars, dyndbg
Convert printk's to dev_dbg. Fix tabs (8 chars) and wrap lines to fit within 80 chars, according to kernel standards.pull/10/head
parent
5e2d8da943
commit
d6cdbfc9bb
|
@ -5,3 +5,5 @@ otgcontrol-objs += otgcontrol_fsm.o
|
|||
otgcontrol-objs += otgcontrol_onewire.o
|
||||
otgcontrol-objs += otgcontrol_charging_ctrl.o
|
||||
otgcontrol-objs += otgcontrol_dr_mode.o
|
||||
|
||||
ccflags-$(CONFIG_RM_OTGCONTROL) += -DDEBUG
|
||||
|
|
|
@ -1,62 +1,80 @@
|
|||
#include "otgcontrol_charging_ctrl.h"
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/power_supply.h>
|
||||
|
||||
int otgcontrol_change_otg_charge_mode(struct rm_otgcontrol_data *otgc_data, int mode)
|
||||
int otgcontrol_change_otg_charge_mode(struct rm_otgcontrol_data *otgc_data,
|
||||
int mode)
|
||||
{
|
||||
int ret;
|
||||
union power_supply_propval property_val;
|
||||
|
||||
printk("%s: Enter\n", __func__);
|
||||
|
||||
switch(mode)
|
||||
{
|
||||
case OTG1_CHARGERMODE_CHARGE:
|
||||
printk("%s: Setting OTG1 chargermode (CHARGE)\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting OTG1 chargermode (CHARGE)\n",
|
||||
__func__);
|
||||
|
||||
property_val.intval = POWER_SUPPLY_MODE_CHARGER;
|
||||
ret = power_supply_set_property(otgc_data->pdata->vbus_supply,
|
||||
POWER_SUPPLY_PROP_CHARGER_MODE,
|
||||
&property_val);
|
||||
POWER_SUPPLY_PROP_CHARGER_MODE,
|
||||
&property_val);
|
||||
if (ret < 0) {
|
||||
printk("%s: Failed to set charger mode\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to set charger mode\n",
|
||||
__func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
property_val.intval = 1;
|
||||
ret = power_supply_set_property(otgc_data->pdata->vbus_supply,
|
||||
POWER_SUPPLY_PROP_ONLINE,
|
||||
&property_val);
|
||||
POWER_SUPPLY_PROP_ONLINE,
|
||||
&property_val);
|
||||
if (ret < 0) {
|
||||
printk("%s: Failed to enable charging after changing charger mode\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to enable charging after "
|
||||
"changing charger mode\n",
|
||||
__func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case OTG1_CHARGERMODE_OTG:
|
||||
printk("%s: Setting OTG1 chargermode (OTG)\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting OTG1 chargermode (OTG)\n",
|
||||
__func__);
|
||||
property_val.intval = POWER_SUPPLY_MODE_OTG_SUPPLY;
|
||||
ret = power_supply_set_property(otgc_data->pdata->vbus_supply,
|
||||
POWER_SUPPLY_PROP_CHARGER_MODE,
|
||||
&property_val);
|
||||
POWER_SUPPLY_PROP_CHARGER_MODE,
|
||||
&property_val);
|
||||
if (ret < 0) {
|
||||
printk("%s: Failed to set charger mode\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to set charger mode\n",
|
||||
__func__);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
property_val.intval = 1;
|
||||
ret = power_supply_set_property(otgc_data->pdata->vbus_supply,
|
||||
POWER_SUPPLY_PROP_ONLINE,
|
||||
&property_val);
|
||||
POWER_SUPPLY_PROP_ONLINE,
|
||||
&property_val);
|
||||
if (ret < 0) {
|
||||
printk("%s: Failed to enable charging after changing charger mode\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to enable charging after changing "
|
||||
"charger mode\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printk("%s: Unable to set OTG1 chargermode (invalid mode %d)", __func__, mode);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Unable to set OTG1 chargermode (invalid mode %d)",
|
||||
__func__, mode);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
#include <linux/rm-otgcontrol.h>
|
||||
|
||||
#define OTG1_CHARGERMODE_CHARGE 0
|
||||
#define OTG1_CHARGERMODE_OTG 1
|
||||
#define OTG1_CHARGERMODE_CHARGE 0
|
||||
#define OTG1_CHARGERMODE_OTG 1
|
||||
|
||||
int otgcontrol_change_otg_charge_mode(struct rm_otgcontrol_data *otgc_data,
|
||||
int mode);
|
||||
int mode);
|
||||
|
||||
#endif /* __OTGCONTROL_CHARGING_CTRL_H__ */
|
||||
|
|
|
@ -12,18 +12,34 @@ int otgcontrol_init_extcon(struct rm_otgcontrol_data *otgc_data)
|
|||
{
|
||||
int ret;
|
||||
|
||||
printk("%s: Allocating extcon device\n", __func__);
|
||||
otgc_data->extcon_dev = devm_extcon_dev_allocate(otgc_data->dev, usb_extcon_cable);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Allocating extcon device\n",
|
||||
__func__);
|
||||
|
||||
otgc_data->extcon_dev = devm_extcon_dev_allocate(otgc_data->dev,
|
||||
usb_extcon_cable);
|
||||
if (IS_ERR(otgc_data->extcon_dev)) {
|
||||
dev_err(otgc_data->dev, "%s: failed to allocate extcon device\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: failed to allocate extcon device\n",
|
||||
__func__);
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
printk("%s: Registering extcon device\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Registering extcon device\n",
|
||||
__func__);
|
||||
|
||||
ret = devm_extcon_dev_register(otgc_data->dev, otgc_data->extcon_dev);
|
||||
if (ret < 0) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to register extcon device\n", __func__);
|
||||
printk("%s: De-allocating extcon device\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to register extcon device\n",
|
||||
__func__);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: De-allocating extcon device\n",
|
||||
__func__);
|
||||
|
||||
kfree(otgc_data->extcon_dev);
|
||||
otgc_data->extcon_dev = NULL;
|
||||
return ret;
|
||||
|
@ -46,17 +62,33 @@ int otgcontrol_set_dr_mode(struct rm_otgcontrol_data *otgc_data, int mode)
|
|||
switch(mode)
|
||||
{
|
||||
case OTG1_DR_MODE__DEVICE:
|
||||
printk("%s: Switching OTG1 DR mode -> DEVICE\n", __func__);
|
||||
return extcon_set_state_sync(otgc_data->extcon_dev, EXTCON_USB_HOST, false);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Switching OTG1 DR mode -> DEVICE\n",
|
||||
__func__);
|
||||
|
||||
return extcon_set_state_sync(otgc_data->extcon_dev,
|
||||
EXTCON_USB_HOST,
|
||||
false);
|
||||
|
||||
break;
|
||||
|
||||
case OTG1_DR_MODE__HOST:
|
||||
printk("%s: Switching OTG1 DR mode -> HOST\n", __func__);
|
||||
return extcon_set_state_sync(otgc_data->extcon_dev, EXTCON_USB_HOST, true);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Switching OTG1 DR mode -> HOST\n",
|
||||
__func__);
|
||||
|
||||
return extcon_set_state_sync(otgc_data->extcon_dev,
|
||||
EXTCON_USB_HOST,
|
||||
true);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
printk("%s: unable to switch OTG1 DR mode (unknown mode %d)\n", __func__, mode);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: unable to switch OTG1 DR mode (unknown mode %d)\n",
|
||||
__func__,
|
||||
mode);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <linux/rm-otgcontrol.h>
|
||||
|
||||
#define OTG1_DR_MODE__DEVICE 0
|
||||
#define OTG1_DR_MODE__HOST 1
|
||||
#define OTG1_DR_MODE__DEVICE 0
|
||||
#define OTG1_DR_MODE__HOST 1
|
||||
|
||||
int otgcontrol_init_extcon(struct rm_otgcontrol_data *otgc_data);
|
||||
void otgcontrol_uninit_extcon(struct rm_otgcontrol_data *otgc_data);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,7 +4,9 @@
|
|||
#include <linux/rm-otgcontrol.h>
|
||||
|
||||
int otgcontrol_init_fsm(struct rm_otgcontrol_data *otgc_data);
|
||||
int otgcontrol_handleInput(struct rm_otgcontrol_data *otgc_data, int signal, void *param);
|
||||
int otgcontrol_handleInput(struct rm_otgcontrol_data *otgc_data,
|
||||
int signal,
|
||||
void *param);
|
||||
|
||||
#define OTG_MODE__MANUAL_CONTROL 0
|
||||
#define OTG_MODE__ONEWIRE_AUTH 1
|
||||
|
|
|
@ -7,15 +7,13 @@
|
|||
* Released under the GPL version 2 only.
|
||||
*
|
||||
*/
|
||||
/* Internal includes */
|
||||
#include <linux/rm-otgcontrol.h>
|
||||
|
||||
#include "otgcontrol_sysfs.h"
|
||||
#include "otgcontrol_fsm.h"
|
||||
#include "otgcontrol_dr_mode.h"
|
||||
#include "otgcontrol_onewire.h"
|
||||
|
||||
/* Required Linux includes */
|
||||
#include <linux/rm-otgcontrol.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/module.h>
|
||||
|
@ -31,50 +29,63 @@
|
|||
#include <linux/string.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/of_gpio.h>
|
||||
|
||||
/* Sysfs */
|
||||
#include <linux/kobject.h>
|
||||
|
||||
/* Device Tree */
|
||||
#include <linux/io.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_irq.h>
|
||||
|
||||
/* Linking to charger/vbus supply driver */
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/power_supply.h>
|
||||
|
||||
/* Faking of VID signal to otg driver */
|
||||
#include <linux/extcon.h>
|
||||
|
||||
static int rm_otgcontrol_init(struct rm_otgcontrol_data *otgc_data)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
printk("%s: Initiating sysfs nodes\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Initiating sysfs nodes\n",
|
||||
__func__);
|
||||
|
||||
ret = otgcontrol_init_sysfs_nodes(otgc_data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
printk("%s: Initiating extcon device to control USB OTG dr mode\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Initiating extcon device to control USB OTG dr mode\n",
|
||||
__func__);
|
||||
|
||||
ret = otgcontrol_init_extcon(otgc_data);
|
||||
if (ret < 0) {
|
||||
printk("%s: Failed to initiate extron (%d)\n", __func__, ret);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to initiate extron (%d)\n",
|
||||
__func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
printk("%s: Initiating onewire state and setting to default state (GPIO)\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Initiating onewire state and setting to default state "
|
||||
"(GPIO)\n",
|
||||
__func__);
|
||||
|
||||
ret = otgcontrol_init_one_wire_mux_state(otgc_data);
|
||||
if (ret < 0) {
|
||||
printk("%s: Failed to initiate onewire pincontrol configuration\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to initiate onewire pincontrol "
|
||||
"configuration\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
printk("%s: Initiating one-wire gpio irq\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Initiating one-wire gpio irq\n",
|
||||
__func__);
|
||||
|
||||
ret = otgcontrol_init_gpio_irq(otgc_data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
printk("%s: Initiating fsm to start in AUTHORIZED MODE !!\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Initiating fsm to start in AUTHORIZED MODE !!\n",
|
||||
__func__);
|
||||
|
||||
ret = otgcontrol_init_fsm(otgc_data);
|
||||
return ret;
|
||||
}
|
||||
|
@ -88,61 +99,111 @@ static int rm_otgcontrol_parse_dt(struct rm_otgcontrol_data *otgc_data)
|
|||
const char *vbus_supply_name;
|
||||
int ret = 0;
|
||||
|
||||
printk("[---- SBA ----] %s: Enter\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Enter\n",
|
||||
__func__);
|
||||
|
||||
if (of_find_property(np, "vbus-supply", NULL)) {
|
||||
printk("%s: Found vbus-supply property, trying to get get vbus powersupply by phandle\n", __func__);
|
||||
pdata->vbus_supply = power_supply_get_by_phandle(np, "vbus-supply");
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Found vbus-supply property, "
|
||||
"trying to get get vbus powersupply by phandle\n",
|
||||
__func__);
|
||||
|
||||
pdata->vbus_supply = power_supply_get_by_phandle(np,
|
||||
"vbus-supply");
|
||||
if (IS_ERR_OR_NULL(pdata->vbus_supply)) {
|
||||
printk("[---- SBA ----] %s: vbus supply not ready, defering probe\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: vbus supply not ready, defering probe\n",
|
||||
__func__);
|
||||
return -EPROBE_DEFER;
|
||||
}
|
||||
}
|
||||
else if (of_find_property(np, "vbus-supply-name", NULL)) {
|
||||
printk("[---- SBA ----] %s: Found vbus-supply-name property, trying to read it\n", __func__);
|
||||
ret = of_property_read_string(np, "vbus-supply-name", &vbus_supply_name);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Found vbus-supply-name property, "
|
||||
"trying to read it\n",
|
||||
__func__);
|
||||
|
||||
ret = of_property_read_string(np,
|
||||
"vbus-supply-name",
|
||||
&vbus_supply_name);
|
||||
if (ret) {
|
||||
printk("[---- SBA ----] %s: Failed to read property vbus-supply-name (code %d)\n", __func__, ret);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to read property vbus-supply-name "
|
||||
"(code %d)\n",
|
||||
__func__, ret);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
printk("[---- SBA ----] %s: Read vbus-supply-name: %s, trying to get reference to it\n", __func__, vbus_supply_name);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Read vbus-supply-name: %s, "
|
||||
"trying to get reference to it\n",
|
||||
__func__, vbus_supply_name);
|
||||
|
||||
pdata->vbus_supply = power_supply_get_by_name(vbus_supply_name);
|
||||
if (IS_ERR(pdata->vbus_supply)) {
|
||||
printk("[---- SBA ----] %s: vbus supply not ready, defering probe\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: vbus supply not ready, defering probe\n",
|
||||
__func__);
|
||||
return -EPROBE_DEFER;
|
||||
}
|
||||
}
|
||||
else {
|
||||
printk("[---- SBA ----] %s: Required vbus-supply-name property not given !\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Required vbus-supply-name property not given !\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
printk("[---- SBA ----] %s: Got pointer to vbus-supply\n", __func__);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Got pointer to vbus-supply\n",
|
||||
__func__);
|
||||
|
||||
if (of_find_property(np, "one-wire-tty-name", NULL)) {
|
||||
printk("[---- SBA ----] %s: Found one-wire-tty-name property, trying to read it\n", __func__);
|
||||
ret = of_property_read_string(np, "one-wire-tty-name", &otgc_data->one_wire_tty_name);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Found one-wire-tty-name property, "
|
||||
"trying to read it\n",
|
||||
__func__);
|
||||
|
||||
ret = of_property_read_string(np,
|
||||
"one-wire-tty-name",
|
||||
&otgc_data->one_wire_tty_name);
|
||||
if (ret) {
|
||||
printk("[---- SBA ----] %s: Failed to read property one-wire-tty-name (code %d)\n", __func__, ret);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to read property one-wire-tty-name "
|
||||
"(code %d)\n",
|
||||
__func__, ret);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
printk("%s: required property one-wire-tty-name not given !\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: required property one-wire-tty-name not given !\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (of_find_property(np, "one-wire-gpios", NULL)) {
|
||||
printk("[---- SBA ----] %s: Found one-wire-gpio property, trying to read it\n", __func__);
|
||||
otgc_data->one_wire_gpio = devm_gpiod_get(otgc_data->dev, "one-wire", GPIOD_IN);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Found one-wire-gpio property, trying to read it\n",
|
||||
__func__);
|
||||
|
||||
otgc_data->one_wire_gpio = devm_gpiod_get(otgc_data->dev,
|
||||
"one-wire",
|
||||
GPIOD_IN);
|
||||
if (IS_ERR(otgc_data->one_wire_gpio)) {
|
||||
printk("%s: Failed to read property one-wire-gpio (code %ld)\n", __func__, PTR_ERR(otgc_data->one_wire_gpio));
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to read property one-wire-gpio "
|
||||
"(code %ld)\n",
|
||||
__func__,
|
||||
PTR_ERR(otgc_data->one_wire_gpio));
|
||||
return PTR_ERR(otgc_data->one_wire_gpio);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printk("%s: required property one-wire-gpio not given !\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: required property one-wire-gpio not given !\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -157,21 +218,35 @@ static int rm_otgcontrol_probe(struct platform_device *pdev)
|
|||
|
||||
int ret = 0;
|
||||
|
||||
printk("[---- SBA ----] %s: Enter:\n", __func__);
|
||||
dev_dbg(&pdev->dev,
|
||||
"%s: rM OTGCONTROL Driver Loading\n",
|
||||
__func__);
|
||||
|
||||
pr_info("%s: rM OTGCONTROL Driver Loading\n", __func__);
|
||||
dev_dbg(&pdev->dev,
|
||||
"%s: Allocating otgcontrol_data\n",
|
||||
__func__);
|
||||
|
||||
printk("[---- SBA ----] %s: Allocating otgcontrol_data\n", __func__);
|
||||
otgc_data = devm_kzalloc(&pdev->dev, sizeof(struct rm_otgcontrol_data), GFP_KERNEL);
|
||||
otgc_data = devm_kzalloc(&pdev->dev,
|
||||
sizeof(struct rm_otgcontrol_data),
|
||||
GFP_KERNEL);
|
||||
if (!otgc_data) {
|
||||
printk("[---- SBA ----] %s: Failed to allocate otgc_data\n", __func__);
|
||||
dev_err(&pdev->dev,
|
||||
"%s: Failed to allocate otgc_data\n",
|
||||
__func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
printk("[---- SBA ----] %s: Allocating otgcontrol_data\n", __func__);
|
||||
pdata = devm_kzalloc(&pdev->dev, sizeof(struct rm_otgcontrol_platform_data), GFP_KERNEL);
|
||||
dev_dbg(&pdev->dev,
|
||||
"%s: Allocating otgcontrol_data\n",
|
||||
__func__);
|
||||
|
||||
pdata = devm_kzalloc(&pdev->dev,
|
||||
sizeof(struct rm_otgcontrol_platform_data),
|
||||
GFP_KERNEL);
|
||||
if (unlikely(!pdata)) {
|
||||
pr_err("[---- SBA ----] %s: Failed to allocate pdata\n", __func__);
|
||||
dev_err(&pdev->dev,
|
||||
"%s: Failed to allocate pdata\n",
|
||||
__func__);
|
||||
pdata = ERR_PTR(-ENOMEM);
|
||||
ret = -ENOMEM;
|
||||
goto error_1;
|
||||
|
@ -181,24 +256,46 @@ static int rm_otgcontrol_probe(struct platform_device *pdev)
|
|||
otgc_data->pdata = pdata;
|
||||
|
||||
#if defined(CONFIG_OF)
|
||||
printk("[---- SBA ---] %s: Reading platform data from devicetree\n", __func__);
|
||||
dev_dbg(&pdev->dev,
|
||||
"%s: Reading platform data from devicetree\n",
|
||||
__func__);
|
||||
|
||||
ret = rm_otgcontrol_parse_dt(otgc_data);
|
||||
if (ret < 0) {
|
||||
pr_err("[---- SBA ----] %s: Failed to load platform data from devicetree\n", __func__);
|
||||
dev_err(&pdev->dev,
|
||||
"%s: Failed to load platform data from devicetree, "
|
||||
"code %d\n",
|
||||
__func__,
|
||||
ret);
|
||||
goto error_2;
|
||||
}
|
||||
#else
|
||||
printk("[---- SBA ----] %s: Driver does not support non-dt configuration\n", __func__);
|
||||
dev_dbg(&pdev->dev,
|
||||
"%s: Driver does not support non-dt configuration\n",
|
||||
__func__);
|
||||
ret = -ENOTSUP;
|
||||
goto error_2;
|
||||
#endif
|
||||
|
||||
printk("[---- SBA ----] %s: Setting otgc_data reference in pdev, and initiating\n", __func__);
|
||||
dev_dbg(&pdev->dev,
|
||||
"%s: Setting otgc_data reference in pdev, and initiating\n",
|
||||
__func__);
|
||||
|
||||
ret = rm_otgcontrol_init(otgc_data);
|
||||
if(ret < 0)
|
||||
if(ret < 0) {
|
||||
dev_err(&pdev->dev,
|
||||
"%s: Failed to init otgcontrol, "
|
||||
"code %d\n",
|
||||
__func__,
|
||||
ret);
|
||||
goto error_3;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, otgc_data);
|
||||
|
||||
dev_info(&pdev->dev,
|
||||
"Loaded successfully !\n");
|
||||
|
||||
return 0;
|
||||
|
||||
error_3:
|
||||
|
@ -220,24 +317,34 @@ static int rm_otgcontrol_remove(struct platform_device *pdev)
|
|||
{
|
||||
struct rm_otgcontrol_data *otgc_data = platform_get_drvdata(pdev);
|
||||
|
||||
printk("[---- SBA ----]otgcontrol1 %s Enter:\n", __func__);
|
||||
|
||||
printk("%s: Un-initializing sysfs nodes\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Un-initializing sysfs nodes\n",
|
||||
__func__);
|
||||
otgcontrol_uninit_sysfs_nodes(otgc_data);
|
||||
|
||||
printk("%s: Un-initializing extcon device\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Un-initializing extcon device\n",
|
||||
__func__);
|
||||
otgcontrol_uninit_extcon(otgc_data);
|
||||
|
||||
printk("%s: Un-initializing one-wire pinctrl\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Un-initializing one-wire pinctrl\n",
|
||||
__func__);
|
||||
otgcontrol_uninit_one_wire_mux_state(otgc_data);
|
||||
|
||||
printk("%s: Un-initialize gpio irq\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Un-initialize gpio irq\n",
|
||||
__func__);
|
||||
otgcontrol_uninit_gpio_irq(otgc_data);
|
||||
|
||||
printk("%s: Freeing otgc->pdata\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Freeing otgc->pdata\n",
|
||||
__func__);
|
||||
devm_kfree(&pdev->dev, otgc_data->pdata);
|
||||
|
||||
printk("%s: Freeing otgc\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Freeing otgc\n",
|
||||
__func__);
|
||||
devm_kfree(&pdev->dev, otgc_data);
|
||||
|
||||
return 0;
|
||||
|
@ -246,14 +353,14 @@ static int rm_otgcontrol_remove(struct platform_device *pdev)
|
|||
#if defined CONFIG_PM
|
||||
static int rm_otgcontrol_suspend(struct device *dev)
|
||||
{
|
||||
printk("[---- SBA ----] %s Enter:\n", __func__);
|
||||
dev_dbg(dev, "%s Enter:\n", __func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rm_otgcontrol_resume(struct device *dev)
|
||||
{
|
||||
printk("[---- SBA ----] %s Enter:\n", __func__);
|
||||
dev_dbg(dev, "%s Enter:\n", __func__);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -271,12 +378,12 @@ MODULE_DEVICE_TABLE(of, rm_otgcontrol_dt_ids);
|
|||
#endif
|
||||
|
||||
static SIMPLE_DEV_PM_OPS(rm_otgcontrol_pm_ops,
|
||||
rm_otgcontrol_suspend,
|
||||
rm_otgcontrol_resume);
|
||||
rm_otgcontrol_suspend,
|
||||
rm_otgcontrol_resume);
|
||||
|
||||
static struct platform_driver rm_otgcontrol_driver = {
|
||||
.driver = {
|
||||
.name = "rM OTG Control",
|
||||
.driver = {
|
||||
.name = "rm_otg_control",
|
||||
.owner = THIS_MODULE,
|
||||
#ifdef CONFIG_PM
|
||||
.pm = &rm_otgcontrol_pm_ops,
|
||||
|
@ -293,17 +400,23 @@ static int __init otgcontrol_init(void)
|
|||
{
|
||||
int ret;
|
||||
|
||||
printk("%s: Registering platform driver 'rm-otgcontrol'\n", __func__);
|
||||
pr_debug("%s: Registering platform driver 'rm-otgcontrol'\n",
|
||||
__func__);
|
||||
|
||||
ret = platform_driver_register(&rm_otgcontrol_driver);
|
||||
if (ret < 0)
|
||||
printk("%s: Failed to register platform driver 'rm-otgcontrol', code %d\n", __func__, ret);
|
||||
pr_err("%s: Failed to register platform driver, code %d\n",
|
||||
__func__,
|
||||
ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit otgcontrol_exit(void)
|
||||
{
|
||||
printk("%s: Unregistering platform driver 'rm-otgcontrol'\n", __func__);
|
||||
pr_debug("%s: Unregistering platform driver 'rm-otgcontrol'\n",
|
||||
__func__);
|
||||
|
||||
platform_driver_unregister(&rm_otgcontrol_driver);
|
||||
}
|
||||
|
||||
|
@ -311,6 +424,7 @@ module_init(otgcontrol_init);
|
|||
module_exit(otgcontrol_exit);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_DESCRIPTION("reMarkable OTG control driver, to enable authentication of devices connecting through the USB OTG interface");
|
||||
MODULE_DESCRIPTION("reMarkable OTG control driver, to enable authentication of "
|
||||
"devices connecting through the USB OTG interface");
|
||||
MODULE_VERSION("1.0");
|
||||
MODULE_AUTHOR("Steinar Bakkemo <steinar.bakkemo@remarkable.no");
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#include "otgcontrol_fsm.h"
|
||||
|
||||
#include <linux/export.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/pinctrl/consumer.h>
|
||||
#include <linux/irq.h>
|
||||
|
@ -11,47 +10,78 @@
|
|||
#include <linux/gpio/consumer.h>
|
||||
#include <linux/fs.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/mutex.h>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#define ONE_WIRE_GPIO_DEBOUNCE_MS 500 /* ms */
|
||||
#define ONE_WIRE_GPIO_DEBOUNCE_MS 500 /* ms */
|
||||
|
||||
int otgcontrol_init_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
pr_info("%s: Initiating one-wire pinctrl states\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Initiating one-wire pinctrl states\n",
|
||||
__func__);
|
||||
|
||||
otgc_data->one_wire_pinctrl = devm_pinctrl_get(otgc_data->dev);
|
||||
if (IS_ERR(otgc_data->one_wire_pinctrl)) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to get pinctrl\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to get pinctrl\n",
|
||||
__func__);
|
||||
|
||||
return PTR_ERR(otgc_data->one_wire_pinctrl);
|
||||
}
|
||||
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO] = pinctrl_lookup_state(otgc_data->one_wire_pinctrl, "default");
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO] =
|
||||
pinctrl_lookup_state(otgc_data->one_wire_pinctrl,
|
||||
"default");
|
||||
|
||||
if (IS_ERR(otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO])) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to configure one-wire-gpio state\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to configure one-wire-gpio state\n",
|
||||
__func__);
|
||||
|
||||
devm_pinctrl_put(otgc_data->one_wire_pinctrl);
|
||||
return PTR_ERR(otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO]);
|
||||
}
|
||||
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_TX] = pinctrl_lookup_state(otgc_data->one_wire_pinctrl, "one_wire_uart_tx");
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_TX] =
|
||||
pinctrl_lookup_state(otgc_data->one_wire_pinctrl,
|
||||
"one_wire_uart_tx");
|
||||
|
||||
if (IS_ERR(otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_TX])) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to configure one-wire-uart-tx state\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to configure one-wire-uart-tx state\n",
|
||||
__func__);
|
||||
|
||||
devm_pinctrl_put(otgc_data->one_wire_pinctrl);
|
||||
return PTR_ERR(otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_TX]);
|
||||
}
|
||||
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_RX] = pinctrl_lookup_state(otgc_data->one_wire_pinctrl, "one_wire_uart_rx");
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_RX] =
|
||||
pinctrl_lookup_state(otgc_data->one_wire_pinctrl,
|
||||
"one_wire_uart_rx");
|
||||
|
||||
if (IS_ERR(otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_RX])) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to configure one-wire-uart-rx\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to configure one-wire-uart-rx\n",
|
||||
__func__);
|
||||
|
||||
devm_pinctrl_put(otgc_data->one_wire_pinctrl);
|
||||
return PTR_ERR(otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_RX]);
|
||||
}
|
||||
|
||||
pr_info("%s: Setting default state (GPIO)\n", __func__);
|
||||
ret = pinctrl_select_state(otgc_data->one_wire_pinctrl, otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO]);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting default state (GPIO)\n",
|
||||
__func__);
|
||||
|
||||
ret = pinctrl_select_state(
|
||||
otgc_data->one_wire_pinctrl,
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO]);
|
||||
if (ret < 0) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to set default state (GPIO)\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to set default state (GPIO)\n",
|
||||
__func__);
|
||||
|
||||
devm_pinctrl_put(otgc_data->one_wire_pinctrl);
|
||||
return ret;
|
||||
}
|
||||
|
@ -60,47 +90,72 @@ int otgcontrol_init_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data)
|
|||
|
||||
void otgcontrol_uninit_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data)
|
||||
{
|
||||
if ((otgc_data->one_wire_pinctrl != NULL) && !IS_ERR(otgc_data->one_wire_pinctrl)) {
|
||||
if ((otgc_data->one_wire_pinctrl != NULL) &&
|
||||
!IS_ERR(otgc_data->one_wire_pinctrl)) {
|
||||
devm_pinctrl_put(otgc_data->one_wire_pinctrl);
|
||||
otgc_data->one_wire_pinctrl = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int otgcontrol_switch_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data, int state)
|
||||
int otgcontrol_switch_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data,
|
||||
int state)
|
||||
{
|
||||
int ret;
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case OTG1_ONEWIRE_STATE__GPIO:
|
||||
pr_info("%s: Switching onewire state -> GPIO\n", __func__);
|
||||
ret = pinctrl_select_state(otgc_data->one_wire_pinctrl, otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO]);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Switching onewire state -> GPIO\n",
|
||||
__func__);
|
||||
|
||||
ret = pinctrl_select_state(
|
||||
otgc_data->one_wire_pinctrl,
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__GPIO]);
|
||||
if (ret < 0) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to set pinctrl state\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to set pinctrl state\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case OTG1_ONEWIRE_STATE__UART_RX:
|
||||
pr_info("%s: Switching onewire state -> UART RX\n", __func__);
|
||||
ret = pinctrl_select_state(otgc_data->one_wire_pinctrl, otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_RX]);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Switching onewire state -> UART RX\n",
|
||||
__func__);
|
||||
|
||||
ret = pinctrl_select_state(
|
||||
otgc_data->one_wire_pinctrl,
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_RX]);
|
||||
if (ret < 0) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to set pinctrl state\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to set pinctrl state\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case OTG1_ONEWIRE_STATE__UART_TX:
|
||||
pr_info("%s: switching onewire state -> UART TX\n", __func__);
|
||||
ret = pinctrl_select_state(otgc_data->one_wire_pinctrl, otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_TX]);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: switching onewire state -> UART TX\n",
|
||||
__func__);
|
||||
|
||||
ret = pinctrl_select_state(
|
||||
otgc_data->one_wire_pinctrl,
|
||||
otgc_data->one_wire_pinctrl_states[OTG1_ONEWIRE_STATE__UART_TX]);
|
||||
if (ret < 0) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to set pinctrl state\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to set pinctrl state\n",
|
||||
__func__);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
dev_err(otgc_data->dev, "%s: unable to switch onewire state (unknown state %d)\n", __func__, state);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: unable to switch onewire state (unknown state %d)\n",
|
||||
__func__, state);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -131,50 +186,85 @@ int otgcontrol_init_gpio_irq(struct rm_otgcontrol_data *otgc_data)
|
|||
{
|
||||
int ret;
|
||||
|
||||
pr_info("%s: Setting local gpio debounce jiffies\n", __func__);
|
||||
otgc_data->one_wire_gpio_debounce_jiffies = msecs_to_jiffies(ONE_WIRE_GPIO_DEBOUNCE_MS);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting local gpio debounce jiffies\n",
|
||||
__func__);
|
||||
|
||||
pr_info("%s: Initiating irq worker\n", __func__);
|
||||
INIT_DELAYED_WORK(&otgc_data->one_wire_gpio_irq_work_queue, otgcontrol_gpio_irq_work);
|
||||
otgc_data->one_wire_gpio_debounce_jiffies =
|
||||
msecs_to_jiffies(ONE_WIRE_GPIO_DEBOUNCE_MS);
|
||||
|
||||
pr_info("%s: Getting IRQ from given gpio (%d)\n",
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Initiating irq worker\n",
|
||||
__func__);
|
||||
|
||||
INIT_DELAYED_WORK(&otgc_data->one_wire_gpio_irq_work_queue,
|
||||
otgcontrol_gpio_irq_work);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Getting IRQ from given gpio (%d)\n",
|
||||
__func__,
|
||||
desc_to_gpio(otgc_data->one_wire_gpio));
|
||||
|
||||
otgc_data->one_wire_gpio_irq = gpiod_to_irq(otgc_data->one_wire_gpio);
|
||||
if (otgc_data->one_wire_gpio_irq < 0) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to get irq for given gpio (%d)\n",
|
||||
__func__,
|
||||
desc_to_gpio(otgc_data->one_wire_gpio));
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to get irq for given gpio (%d)\n",
|
||||
__func__,
|
||||
desc_to_gpio(otgc_data->one_wire_gpio));
|
||||
return otgc_data->one_wire_gpio_irq;
|
||||
}
|
||||
|
||||
otgc_data->one_wire_gpio_state = otgcontrol_get_current_gpio_state(otgc_data);
|
||||
pr_info("%s: Current GPIO state: %s\n", __func__, otgcontrol_gpio_state_name(otgc_data->one_wire_gpio_state));
|
||||
otgc_data->one_wire_gpio_state =
|
||||
otgcontrol_get_current_gpio_state(otgc_data);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Current GPIO state: %s\n",
|
||||
__func__,
|
||||
otgcontrol_gpio_state_name(otgc_data->one_wire_gpio_state));
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Clearing is-handling flag\n",
|
||||
__func__);
|
||||
|
||||
pr_info("%s: Clearing is-handling flag\n", __func__);
|
||||
otgc_data->one_wire_gpio_irq_is_handling = false;
|
||||
|
||||
pr_info("%s: Requesting threaded irq\n", __func__);
|
||||
ret = devm_request_threaded_irq(otgc_data->dev, otgc_data->one_wire_gpio_irq, NULL,
|
||||
otgcontrol_gpio_irq_handler,
|
||||
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
||||
"one_wire_gpio_irq", otgc_data);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Requesting threaded irq\n",
|
||||
__func__);
|
||||
|
||||
ret = devm_request_threaded_irq(
|
||||
otgc_data->dev,
|
||||
otgc_data->one_wire_gpio_irq,
|
||||
NULL,
|
||||
otgcontrol_gpio_irq_handler,
|
||||
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
||||
"one_wire_gpio_irq",
|
||||
otgc_data);
|
||||
if (ret < 0) {
|
||||
dev_err(otgc_data->dev, "%s: Failed to request handler for IRQ (%d) given for GPIO (%d)\n",
|
||||
__func__,
|
||||
otgc_data->one_wire_gpio_irq,
|
||||
desc_to_gpio(otgc_data->one_wire_gpio));
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: Failed to request handler for IRQ (%d) "
|
||||
"given for GPIO (%d)\n",
|
||||
__func__,
|
||||
otgc_data->one_wire_gpio_irq,
|
||||
desc_to_gpio(otgc_data->one_wire_gpio));
|
||||
return ret;
|
||||
}
|
||||
mutex_lock(&otgc_data->lock);
|
||||
otgc_data->one_wire_gpio_irq_is_active = true;
|
||||
mutex_unlock(&otgc_data->lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void otgcontrol_uninit_gpio_irq(struct rm_otgcontrol_data *otgc_data)
|
||||
{
|
||||
printk("%s: Freeing irq\n", __func__);
|
||||
devm_free_irq(otgc_data->dev, otgc_data->one_wire_gpio_irq, otgc_data);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Freeing irq\n",
|
||||
__func__);
|
||||
|
||||
devm_free_irq(otgc_data->dev,
|
||||
otgc_data->one_wire_gpio_irq,
|
||||
otgc_data);
|
||||
}
|
||||
|
||||
void otgcontrol_activate_gpio_irq(struct rm_otgcontrol_data *otgc_data)
|
||||
|
@ -198,13 +288,22 @@ static irqreturn_t otgcontrol_gpio_irq_handler(int irq, void *data)
|
|||
struct rm_otgcontrol_data *otgc_data = (struct rm_otgcontrol_data*)data;
|
||||
|
||||
if (otgc_data->one_wire_gpio_irq_is_handling) {
|
||||
pr_info("%s: Is already handling irq, ignoring this\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Is already handling irq, ignoring this\n",
|
||||
__func__);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
else {
|
||||
pr_info("%s: Queueing IRQ handling for execution in %d ms\n", __func__, ONE_WIRE_GPIO_DEBOUNCE_MS);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Queueing IRQ handling for execution in %d ms\n",
|
||||
__func__,
|
||||
ONE_WIRE_GPIO_DEBOUNCE_MS);
|
||||
|
||||
otgc_data->one_wire_gpio_irq_is_handling = true;
|
||||
queue_delayed_work(system_power_efficient_wq, &otgc_data->one_wire_gpio_irq_work_queue, otgc_data->one_wire_gpio_debounce_jiffies);
|
||||
|
||||
queue_delayed_work(system_power_efficient_wq,
|
||||
&otgc_data->one_wire_gpio_irq_work_queue,
|
||||
otgc_data->one_wire_gpio_debounce_jiffies);
|
||||
}
|
||||
|
||||
return IRQ_HANDLED;
|
||||
|
@ -214,26 +313,50 @@ static void otgcontrol_gpio_irq_work(struct work_struct *work)
|
|||
{
|
||||
int cur_gpio_state;
|
||||
|
||||
struct delayed_work *delayed_work = container_of(work, struct delayed_work, work);
|
||||
struct rm_otgcontrol_data *otgc_data = container_of(delayed_work, struct rm_otgcontrol_data, one_wire_gpio_irq_work_queue);
|
||||
struct delayed_work *delayed_work =
|
||||
container_of(work,
|
||||
struct delayed_work,
|
||||
work);
|
||||
|
||||
struct rm_otgcontrol_data *otgc_data =
|
||||
container_of(delayed_work,
|
||||
struct rm_otgcontrol_data,
|
||||
one_wire_gpio_irq_work_queue);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Checking current gpio state\n",
|
||||
__func__);
|
||||
|
||||
pr_info("%s: Checking current gpio state\n", __func__);
|
||||
cur_gpio_state = otgcontrol_get_current_gpio_state(otgc_data);
|
||||
if (cur_gpio_state != otgc_data->one_wire_gpio_state) {
|
||||
pr_info("%s: GPIO state changed -> %s\n", __func__, otgcontrol_gpio_state_name(cur_gpio_state));
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: GPIO state changed -> %s\n",
|
||||
__func__,
|
||||
otgcontrol_gpio_state_name(cur_gpio_state));
|
||||
|
||||
otgc_data->one_wire_gpio_state = cur_gpio_state;
|
||||
|
||||
if (otgc_data->one_wire_gpio_state == OTG1_ONEWIRE_GPIO_STATE__DEVICE_CONNECTED)
|
||||
otgcontrol_handleInput(otgc_data, OTG1_EVENT__DEVICE_CONNECTED, NULL);
|
||||
if (otgc_data->one_wire_gpio_state ==
|
||||
OTG1_ONEWIRE_GPIO_STATE__DEVICE_CONNECTED)
|
||||
otgcontrol_handleInput(otgc_data,
|
||||
OTG1_EVENT__DEVICE_CONNECTED,
|
||||
NULL);
|
||||
else
|
||||
otgcontrol_handleInput(otgc_data, OTG1_EVENT__DEVICE_DISCONNECTED, NULL);
|
||||
otgcontrol_handleInput(otgc_data,
|
||||
OTG1_EVENT__DEVICE_DISCONNECTED,
|
||||
NULL);
|
||||
}
|
||||
|
||||
pr_info("%s: Resetting is-handling flag\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Resetting is-handling flag\n",
|
||||
__func__);
|
||||
|
||||
otgc_data->one_wire_gpio_irq_is_handling = false;
|
||||
}
|
||||
|
||||
int otgcontrol_onewire_write_tty(struct rm_otgcontrol_data *otgc_data, char *device_name, char *text_to_send)
|
||||
int otgcontrol_onewire_write_tty(struct rm_otgcontrol_data *otgc_data,
|
||||
char *device_name,
|
||||
char *text_to_send)
|
||||
{
|
||||
// Create variables
|
||||
struct file *f;
|
||||
|
@ -245,31 +368,55 @@ int otgcontrol_onewire_write_tty(struct rm_otgcontrol_data *otgc_data, char *dev
|
|||
for(i = 0;i < 128;i++)
|
||||
buf[i] = 0;
|
||||
|
||||
pr_info("%s: Trying to open %s\n", __func__, device_name);
|
||||
dev_dbg(otgc_data->dev, "%s: Trying to open %s\n",
|
||||
__func__,
|
||||
device_name);
|
||||
|
||||
f = filp_open(device_name, O_RDWR, 0);
|
||||
if(f == NULL) {
|
||||
dev_err(otgc_data->dev, "%s: filp_open error!!.\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: filp_open error!!.\n",
|
||||
__func__);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
// Get current segment descriptor
|
||||
pr_info("%s: Getting current segment descriptor\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Getting current segment descriptor\n",
|
||||
__func__);
|
||||
|
||||
fs = get_fs();
|
||||
|
||||
// Set segment descriptor associated to kernel space
|
||||
pr_info("%s: Setting segment descriptor\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting segment descriptor\n",
|
||||
__func__);
|
||||
|
||||
set_fs(get_ds());
|
||||
|
||||
//Write to the file
|
||||
pr_info("%s: Writing '%s' to file\n", __func__, text_to_send);
|
||||
kernel_write(f, text_to_send, strlen(text_to_send), &f->f_pos);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Writing '%s' to file\n",
|
||||
__func__,
|
||||
text_to_send);
|
||||
|
||||
kernel_write(f,
|
||||
text_to_send,
|
||||
strlen(text_to_send),
|
||||
&f->f_pos);
|
||||
// f->f_op->write(f, text_to_send, strlen(text_to_send), &f->f_pos);
|
||||
|
||||
// Restore segment descriptor
|
||||
pr_info("%s: Restoring segment descriptor\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Restoring segment descriptor\n",
|
||||
__func__);
|
||||
|
||||
set_fs(fs);
|
||||
|
||||
pr_info("%s: Closing file\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Closing file\n",
|
||||
__func__);
|
||||
|
||||
filp_close(f,NULL);
|
||||
return 0;
|
||||
}
|
||||
|
@ -285,33 +432,54 @@ int otgcontrol_onewire_read_until_cr(struct rm_otgcontrol_data *otgc_data, char
|
|||
|
||||
f = filp_open(device_name, O_RDONLY, 0);
|
||||
if(f == NULL) {
|
||||
dev_err(otgc_data->dev, "%s: filp_open error!!.\n", __func__);
|
||||
dev_err(otgc_data->dev,
|
||||
"%s: filp_open error!!.\n",
|
||||
__func__);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
|
||||
// Get current segment descriptor
|
||||
pr_info("%s: Getting current segment descriptor\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Getting current segment descriptor\n",
|
||||
__func__);
|
||||
|
||||
fs = get_fs();
|
||||
|
||||
// Set segment descriptor associated to kernel space
|
||||
pr_info("%s: Setting segment descriptor\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting segment descriptor\n",
|
||||
__func__);
|
||||
|
||||
set_fs(get_ds());
|
||||
|
||||
pos = 0;
|
||||
int state = 0;
|
||||
pr_info("%s: Starting read loop\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Starting read loop\n",
|
||||
__func__);
|
||||
do {
|
||||
// Read the file
|
||||
// f->f_op->read(f, &newchar, 1, &f->f_pos);
|
||||
kernel_read(f, &newchar, 1, &f->f_pos);
|
||||
pr_info("%s: <-%c (0x%02x)\n", __func__, newchar, newchar);
|
||||
kernel_read(f,
|
||||
&newchar,
|
||||
1,
|
||||
&f->f_pos);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: <-%c (0x%02x)\n",
|
||||
__func__,
|
||||
newchar, newchar);
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case 0:
|
||||
// Wait :
|
||||
if (newchar == ':') {
|
||||
pr_info("%s: SOF\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: SOF\n",
|
||||
__func__);
|
||||
|
||||
state = 1;
|
||||
}
|
||||
break;
|
||||
|
@ -322,16 +490,29 @@ int otgcontrol_onewire_read_until_cr(struct rm_otgcontrol_data *otgc_data, char
|
|||
}
|
||||
}
|
||||
}while((newchar != '#') && (pos < maxlen));
|
||||
pr_info("%s: Done\n", __func__);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Done\n",
|
||||
__func__);
|
||||
|
||||
// Restore segment descriptor
|
||||
pr_info("%s: Restoring segment descriptor\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Restoring segment descriptor\n",
|
||||
__func__);
|
||||
|
||||
set_fs(fs);
|
||||
|
||||
pr_info("%s: Closing file\n", __func__);
|
||||
filp_close(f,NULL);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Closing file\n",
|
||||
__func__);
|
||||
|
||||
filp_close(f, NULL);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Returning %d bytes read\n",
|
||||
__func__,
|
||||
pos);
|
||||
|
||||
pr_info("%s: Returning %d bytes read\n", __func__, pos);
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,20 +6,18 @@
|
|||
#include <linux/workqueue.h>
|
||||
#include <linux/interrupt.h>
|
||||
|
||||
#define OTG1_ONEWIRE_STATE__GPIO 0
|
||||
#define OTG1_ONEWIRE_STATE__UART_TX 1
|
||||
#define OTG1_ONEWIRE_STATE__UART_RX 2
|
||||
#define OTG1_ONEWIRE_STATE__GPIO 0
|
||||
#define OTG1_ONEWIRE_STATE__UART_TX 1
|
||||
#define OTG1_ONEWIRE_STATE__UART_RX 2
|
||||
|
||||
/********************************************************
|
||||
* State definitions to be used when reading GPIO input
|
||||
********************************************************/
|
||||
#define OTG1_ONEWIRE_GPIO_STATE__DEVICE_CONNECTED 0
|
||||
#define OTG1_ONEWIRE_GPIO_STATE__DEVICE_NOT_CONNECTED 1
|
||||
#define OTG1_ONEWIRE_GPIO_STATE__DEVICE_CONNECTED 0
|
||||
#define OTG1_ONEWIRE_GPIO_STATE__DEVICE_NOT_CONNECTED 1
|
||||
|
||||
int otgcontrol_init_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data);
|
||||
void otgcontrol_uninit_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data);
|
||||
|
||||
int otgcontrol_switch_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data, int newState);
|
||||
int otgcontrol_switch_one_wire_mux_state(struct rm_otgcontrol_data *otgc_data,
|
||||
int newState);
|
||||
int otgcontrol_get_current_gpio_state(struct rm_otgcontrol_data *otgc_data);
|
||||
const char *otgcontrol_gpio_state_name(int state);
|
||||
int otgcontrol_init_gpio_irq(struct rm_otgcontrol_data *otgc_data);
|
||||
|
@ -28,7 +26,12 @@ void otgcontrol_activate_gpio_irq(struct rm_otgcontrol_data *otgc_data);
|
|||
void otgcontrol_deactivate_gpio_irq(struct rm_otgcontrol_data *otgc_data);
|
||||
static irqreturn_t otgcontrol_gpio_irq_handler(int irq, void *data);
|
||||
static void otgcontrol_gpio_irq_work(struct work_struct *work);
|
||||
int otgcontrol_onewire_read_until_cr(struct rm_otgcontrol_data *otgc_data, char *device_name, char *buf, int maxlen);
|
||||
int otgcontrol_onewire_write_tty(struct rm_otgcontrol_data *otgc_data, char *device_name, char *text_to_send);
|
||||
int otgcontrol_onewire_read_until_cr(struct rm_otgcontrol_data *otgc_data,
|
||||
char *device_name,
|
||||
char *buf,
|
||||
int maxlen);
|
||||
int otgcontrol_onewire_write_tty(struct rm_otgcontrol_data *otgc_data,
|
||||
char *device_name,
|
||||
char *text_to_send);
|
||||
|
||||
#endif /* __OTGCONTROL_ONE_WIRE_H__ */
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
#include "otgcontrol_onewire.h"
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/power_supply.h>
|
||||
|
||||
#define to_otgcontrol_data(kobj_attr_ptr, kobj_attr_member) container_of(kobj_attr_ptr, struct rm_otgcontrol_data, kobj_attr_member);
|
||||
#define to_otgcontrol_data(kobj_attr_ptr, kobj_attr_member) \
|
||||
container_of(kobj_attr_ptr, struct rm_otgcontrol_data, kobj_attr_member);
|
||||
|
||||
#define SYSFS_PARENT_NODE NULL
|
||||
#define SYSFS_NODE_NAME "otgcontrol"
|
||||
|
@ -20,8 +20,11 @@
|
|||
#define CONTROL_GROUP_ATTRIBUTE_COUNT 4
|
||||
|
||||
static struct attribute *control_attrs[CONTROL_GROUP_ATTRIBUTE_COUNT + 1] = {
|
||||
NULL, NULL, NULL, NULL, /* CONTROL_GROUP_ATTRIBUTE_COUNT number of initializing NULLs */
|
||||
NULL /* NULL terminating the list */
|
||||
/* CONTROL_GROUP_ATTRIBUTE_COUNT number of initializing NULLs */
|
||||
NULL, NULL, NULL, NULL,
|
||||
|
||||
/* NULL terminating the list */
|
||||
NULL
|
||||
};
|
||||
|
||||
struct attribute_group control_attr_group = {
|
||||
|
@ -30,8 +33,11 @@ struct attribute_group control_attr_group = {
|
|||
};
|
||||
|
||||
struct attribute *status_attrs[STATUS_GROUP_ATTRIBUTE_COUNT + 1] = {
|
||||
NULL, /* STATUS_GROUP_ATTRIBUTE_COUNT number of NULLS */
|
||||
NULL /* NULL terminating the list */
|
||||
/* STATUS_GROUP_ATTRIBUTE_COUNT number of NULLS */
|
||||
NULL,
|
||||
|
||||
/* NULL terminating the list */
|
||||
NULL
|
||||
};
|
||||
|
||||
struct attribute_group status_attr_group = {
|
||||
|
@ -39,73 +45,126 @@ struct attribute_group status_attr_group = {
|
|||
.name = "status"
|
||||
};
|
||||
|
||||
static ssize_t attribute_show(struct kobject *kobj, struct kobj_attribute *attr,
|
||||
char *buf)
|
||||
static ssize_t attribute_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
int var;
|
||||
struct rm_otgcontrol_data *otgc_data;
|
||||
|
||||
printk("%s: Enter\n", __func__);
|
||||
|
||||
if (strcmp(attr->attr.name, "otg1_device_connected") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_device_connected_attribute);
|
||||
printk("%s: Returning cur otg1_device_connected value (%d)\n", __func__, otgc_data->otg1_device_connected);
|
||||
otgc_data = to_otgcontrol_data(attr,
|
||||
otg1_device_connected_attribute);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Returning cur otg1_device_connected value (%d)\n",
|
||||
__func__,
|
||||
otgc_data->otg1_device_connected);
|
||||
|
||||
var = otgc_data->otg1_device_connected;
|
||||
}
|
||||
else if (strcmp(attr->attr.name, "otg1_dr_mode") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_dr_mode_attribute);
|
||||
printk("%s: Returning cur otg1_id_state value (%d)\n", __func__, otgc_data->otg1_dr_mode);
|
||||
otgc_data = to_otgcontrol_data(attr,
|
||||
otg1_dr_mode_attribute);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Returning cur otg1_id_state value (%d)\n",
|
||||
__func__,
|
||||
otgc_data->otg1_dr_mode);
|
||||
|
||||
var = otgc_data->otg1_dr_mode;
|
||||
}
|
||||
else if (strcmp(attr->attr.name, "otg1_chargermode") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_chargermode_attribute);
|
||||
printk("%s: Returning cur otg1_chargermode value (%d)\n", __func__, otgc_data->otg1_chargermode);
|
||||
otgc_data = to_otgcontrol_data(attr,
|
||||
otg1_chargermode_attribute);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Returning cur otg1_chargermode value (%d)\n",
|
||||
__func__,
|
||||
otgc_data->otg1_chargermode);
|
||||
|
||||
var = otgc_data->otg1_chargermode;
|
||||
}
|
||||
else if (strcmp(attr->attr.name, "otg1_controllermode") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_controllermode_attribute);
|
||||
printk("%s: Returning cur otg1_controllermode value (%d)\n", __func__, otgc_data->otg1_controllermode);
|
||||
otgc_data = to_otgcontrol_data(attr,
|
||||
otg1_controllermode_attribute);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Returning cur otg1_controllermode value (%d)\n",
|
||||
__func__,
|
||||
otgc_data->otg1_controllermode);
|
||||
|
||||
var = otgc_data->otg1_controllermode;
|
||||
}
|
||||
else {
|
||||
printk("%s: Invalid attribute name (%s)\n", __func__, attr->attr.name);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Invalid attribute name (%s)\n",
|
||||
__func__,
|
||||
attr->attr.name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return sprintf(buf, "%d\n", var);
|
||||
}
|
||||
|
||||
static ssize_t attribute_store(struct kobject *kobj, struct kobj_attribute *attr,
|
||||
const char *buf, size_t count)
|
||||
static ssize_t attribute_store(struct kobject *kobj,
|
||||
struct kobj_attribute *attr,
|
||||
const char *buf,
|
||||
size_t count)
|
||||
{
|
||||
struct rm_otgcontrol_data *otgc_data;
|
||||
int var, ret;
|
||||
|
||||
printk("%s: Enter\n", __func__);
|
||||
|
||||
ret = kstrtoint(buf, 10, &var);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (strcmp(attr->attr.name, "otg1_dr_mode") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_dr_mode_attribute);
|
||||
printk("%s: Setting new otg1 dr mode (%d)\n", __func__, var);
|
||||
ret = otgcontrol_set_dr_mode(otgc_data, var);
|
||||
otgc_data = to_otgcontrol_data(attr,
|
||||
otg1_dr_mode_attribute);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting new otg1 dr mode (%d)\n",
|
||||
__func__,
|
||||
var);
|
||||
|
||||
ret = otgcontrol_set_dr_mode(otgc_data,
|
||||
var);
|
||||
}
|
||||
else if (strcmp(attr->attr.name, "otg1_chargermode") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_chargermode_attribute);
|
||||
printk("%s: Setting new otg1 chargermode (%d)\n", __func__, var);
|
||||
ret = otgcontrol_change_otg_charge_mode(otgc_data, var);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting new otg1 chargermode (%d)\n",
|
||||
__func__,
|
||||
var);
|
||||
|
||||
ret = otgcontrol_change_otg_charge_mode(otgc_data,
|
||||
var);
|
||||
}
|
||||
else if (strcmp(attr->attr.name, "otg1_controllermode") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_controllermode_attribute);
|
||||
printk("%s: Setting new otg1 controllermode (%d)\n", __func__, var);
|
||||
ret = otgcontrol_handleInput(otgc_data, OTG1_EVENT__MODE_CHANGE_REQUESTED, (void*)&var);
|
||||
otgc_data = to_otgcontrol_data(attr,
|
||||
otg1_controllermode_attribute);
|
||||
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting new otg1 controllermode (%d)\n",
|
||||
__func__,
|
||||
var);
|
||||
|
||||
ret = otgcontrol_handleInput(otgc_data,
|
||||
OTG1_EVENT__MODE_CHANGE_REQUESTED,
|
||||
(void*)&var);
|
||||
}
|
||||
else if (strcmp(attr->attr.name, "otg1_pinctrlstate") == 0) {
|
||||
otgc_data = to_otgcontrol_data(attr, otg1_pinctrlstate_attribute);
|
||||
printk("%s: Setting new pinctrlstate (%d)\n", __func__, var);
|
||||
ret = otgcontrol_switch_one_wire_mux_state(otgc_data, var);
|
||||
otgc_data = to_otgcontrol_data(attr,
|
||||
otg1_pinctrlstate_attribute);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Setting new pinctrlstate (%d)\n",
|
||||
__func__,
|
||||
var);
|
||||
|
||||
ret = otgcontrol_switch_one_wire_mux_state(otgc_data,
|
||||
var);
|
||||
}
|
||||
else {
|
||||
return -EINVAL;
|
||||
|
@ -115,10 +174,15 @@ static ssize_t attribute_store(struct kobject *kobj, struct kobj_attribute *attr
|
|||
}
|
||||
|
||||
void otgcontrol_create_kobj_property(struct kobj_attribute *attr,
|
||||
const char *name,
|
||||
int permission,
|
||||
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf),
|
||||
ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count))
|
||||
const char *name,
|
||||
int permission,
|
||||
ssize_t (*show)(struct kobject *kobj,
|
||||
struct kobj_attribute *attr,
|
||||
char *buf),
|
||||
ssize_t (*store)(struct kobject *kobj,
|
||||
struct kobj_attribute *attr,
|
||||
const char *buf,
|
||||
size_t count))
|
||||
{
|
||||
attr->attr.name = name;
|
||||
attr->attr.mode = VERIFY_OCTAL_PERMISSIONS(S_IRUGO | S_IWUSR);
|
||||
|
@ -131,32 +195,33 @@ int otgcontrol_init_sysfs_nodes(struct rm_otgcontrol_data *otgc_data)
|
|||
struct kobject *otgcontrol_kobj;
|
||||
int retval;
|
||||
|
||||
printk("%s: Enter\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Creating control properties (R/W)\n",
|
||||
__func__);
|
||||
|
||||
printk("%s: Creating control properties (R/W)\n", __func__);
|
||||
otgcontrol_create_kobj_property(&otgc_data->otg1_dr_mode_attribute,
|
||||
"otg1_dr_mode",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
"otg1_dr_mode",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
|
||||
otgcontrol_create_kobj_property(&otgc_data->otg1_chargermode_attribute,
|
||||
"otg1_chargermode",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
"otg1_chargermode",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
|
||||
otgcontrol_create_kobj_property(&otgc_data->otg1_controllermode_attribute,
|
||||
"otg1_controllermode",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
"otg1_controllermode",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
|
||||
otgcontrol_create_kobj_property(&otgc_data->otg1_pinctrlstate_attribute,
|
||||
"otg1_pinctrlstate",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
"otg1_pinctrlstate",
|
||||
S_IRUGO | S_IWUSR,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
|
||||
control_attrs[0] = &otgc_data->otg1_dr_mode_attribute.attr;
|
||||
control_attrs[1] = &otgc_data->otg1_chargermode_attribute.attr;
|
||||
|
@ -164,23 +229,30 @@ int otgcontrol_init_sysfs_nodes(struct rm_otgcontrol_data *otgc_data)
|
|||
control_attrs[3] = &otgc_data->otg1_pinctrlstate_attribute.attr;
|
||||
control_attrs[4] = NULL; /* NULL termination of the list */
|
||||
|
||||
printk("%s: Creating status properties (R)\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Creating status properties (R)\n",
|
||||
__func__);
|
||||
|
||||
otgcontrol_create_kobj_property(&otgc_data->otg1_device_connected_attribute,
|
||||
"otg1_device_connected",
|
||||
S_IRUGO,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
"otg1_device_connected",
|
||||
S_IRUGO,
|
||||
attribute_show,
|
||||
attribute_store);
|
||||
|
||||
status_attrs[0] = &otgc_data->otg1_device_connected_attribute.attr;
|
||||
status_attrs[1] = NULL; /* NULL termination of the list */
|
||||
|
||||
otgcontrol_kobj = kobject_create_and_add(SYSFS_NODE_NAME, SYSFS_PARENT_NODE);
|
||||
otgcontrol_kobj = kobject_create_and_add(SYSFS_NODE_NAME,
|
||||
SYSFS_PARENT_NODE);
|
||||
if (!otgcontrol_kobj)
|
||||
return -ENOMEM;
|
||||
|
||||
/* Create the files associated with this kobject */
|
||||
retval = sysfs_create_group(otgcontrol_kobj, &control_attr_group);
|
||||
retval = sysfs_create_group(otgcontrol_kobj, &status_attr_group);
|
||||
retval = sysfs_create_group(otgcontrol_kobj,
|
||||
&control_attr_group);
|
||||
|
||||
retval = sysfs_create_group(otgcontrol_kobj,
|
||||
&status_attr_group);
|
||||
if (retval) {
|
||||
otgc_data->kobject = otgcontrol_kobj;
|
||||
}
|
||||
|
@ -191,7 +263,10 @@ int otgcontrol_init_sysfs_nodes(struct rm_otgcontrol_data *otgc_data)
|
|||
|
||||
void otgcontrol_uninit_sysfs_nodes(struct rm_otgcontrol_data *otgc_data)
|
||||
{
|
||||
printk("%s: Decrementing kobject refcount\n", __func__);
|
||||
dev_dbg(otgc_data->dev,
|
||||
"%s: Decrementing kobject refcount\n",
|
||||
__func__);
|
||||
|
||||
if((otgc_data->kobject != NULL) && !IS_ERR(otgc_data->kobject)) {
|
||||
sysfs_remove_group(otgc_data->kobject, &control_attr_group);
|
||||
sysfs_remove_group(otgc_data->kobject, &status_attr_group);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/pinctrl/pinctrl.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/extcon.h>
|
||||
|
||||
struct rm_otgcontrol_platform_data {
|
||||
|
@ -10,42 +11,44 @@ struct rm_otgcontrol_platform_data {
|
|||
};
|
||||
|
||||
struct rm_otgcontrol_data {
|
||||
struct device *dev;
|
||||
struct rm_otgcontrol_platform_data *pdata;
|
||||
struct device *dev;
|
||||
struct rm_otgcontrol_platform_data *pdata;
|
||||
|
||||
struct extcon_dev *extcon_dev;
|
||||
struct mutex lock;
|
||||
|
||||
const char *one_wire_tty_name;
|
||||
struct gpio_desc *one_wire_gpio;
|
||||
int one_wire_gpio_irq;
|
||||
unsigned long one_wire_gpio_debounce_jiffies;
|
||||
struct delayed_work one_wire_gpio_irq_work_queue;
|
||||
bool one_wire_gpio_irq_is_active;
|
||||
int one_wire_gpio_state;
|
||||
bool one_wire_gpio_irq_is_handling;
|
||||
struct extcon_dev *extcon_dev;
|
||||
|
||||
int otg_controlstate;
|
||||
int mode_requested;
|
||||
const char *one_wire_tty_name;
|
||||
struct gpio_desc *one_wire_gpio;
|
||||
int one_wire_gpio_irq;
|
||||
unsigned long one_wire_gpio_debounce_jiffies;
|
||||
struct delayed_work one_wire_gpio_irq_work_queue;
|
||||
bool one_wire_gpio_irq_is_active;
|
||||
int one_wire_gpio_state;
|
||||
bool one_wire_gpio_irq_is_handling;
|
||||
|
||||
struct pinctrl* one_wire_pinctrl;
|
||||
struct pinctrl_state* one_wire_pinctrl_states[3];
|
||||
int otg_controlstate;
|
||||
int mode_requested;
|
||||
|
||||
struct kobject* kobject;
|
||||
struct pinctrl* one_wire_pinctrl;
|
||||
struct pinctrl_state* one_wire_pinctrl_states[3];
|
||||
|
||||
struct kobj_attribute otg1_device_connected_attribute;
|
||||
bool otg1_device_connected;
|
||||
struct kobject* kobject;
|
||||
|
||||
struct kobj_attribute otg1_dr_mode_attribute;
|
||||
int otg1_dr_mode;
|
||||
struct kobj_attribute otg1_device_connected_attribute;
|
||||
bool otg1_device_connected;
|
||||
|
||||
struct kobj_attribute otg1_chargermode_attribute;
|
||||
int otg1_chargermode;
|
||||
struct kobj_attribute otg1_dr_mode_attribute;
|
||||
int otg1_dr_mode;
|
||||
|
||||
struct kobj_attribute otg1_controllermode_attribute;
|
||||
int otg1_controllermode;
|
||||
struct kobj_attribute otg1_chargermode_attribute;
|
||||
int otg1_chargermode;
|
||||
|
||||
struct kobj_attribute otg1_pinctrlstate_attribute;
|
||||
int otg1_pinctrlstate;
|
||||
struct kobj_attribute otg1_controllermode_attribute;
|
||||
int otg1_controllermode;
|
||||
|
||||
struct kobj_attribute otg1_pinctrlstate_attribute;
|
||||
int otg1_pinctrlstate;
|
||||
};
|
||||
|
||||
#endif /* __RM_OTGCONTROL_H */
|
||||
|
|
Loading…
Reference in New Issue