mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-10-28 17:12:22 +00:00
Compare commits
1 Commits
1a3955554a
...
wifi-14697
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da2399e065 |
25
feeds/qca-wifi-7/cig-platform-pkg/cig-poe-judgment/Makefile
Normal file
25
feeds/qca-wifi-7/cig-platform-pkg/cig-poe-judgment/Makefile
Normal file
@@ -0,0 +1,25 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=cig-poe-judgment
|
||||
PKG_RELEASE:=1
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define KernelPackage/cig-poe-judgment
|
||||
SUBMENU:=Other modules
|
||||
TITLE:=CIG POE judgment
|
||||
FILES:=$(PKG_BUILD_DIR)/cig_poe_judgment.ko
|
||||
AUTOLOAD:=$(call AutoLoad,99,cig_poe_judgment)
|
||||
endef
|
||||
|
||||
define KernelPackage/cig-poe-judgment/description
|
||||
Find POE type
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(KERNEL_MAKE) M="$(PKG_BUILD_DIR)" modules
|
||||
endef
|
||||
|
||||
$(eval $(call KernelPackage,cig-poe-judgment))
|
||||
@@ -0,0 +1 @@
|
||||
obj-m += cig_poe_judgment.o
|
||||
@@ -0,0 +1,252 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/kthread.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/of_address.h>
|
||||
#include <linux/irqreturn.h>
|
||||
#include <linux/of_gpio.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/of_irq.h>
|
||||
#include <linux/of_platform.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
||||
#define GPIO_MAX 8
|
||||
#define INT_MODE_MASK 0xf0
|
||||
#define DETECT_MODE1 0x3
|
||||
#define DETECT_MODE2 0x4
|
||||
|
||||
enum POE_TYPE {
|
||||
POE_TYPE_AT = 1,
|
||||
POE_TYPE_AF,
|
||||
POE_TYPE_BT,
|
||||
POE_TYPE_DC,
|
||||
POE_TYPE_MAX
|
||||
};
|
||||
|
||||
struct poe_irq_data
|
||||
{
|
||||
struct device *dev;
|
||||
int irq;
|
||||
struct tasklet_struct tasklet;
|
||||
int poe_type;
|
||||
};
|
||||
|
||||
static void *poe_gpio_base;
|
||||
static void *pse_gpio_base;
|
||||
struct poe_irq_data *data = NULL;
|
||||
u32 mode;
|
||||
|
||||
static const struct of_device_id my_of_ids[] = {
|
||||
{.compatible = "poe-judge"},
|
||||
{},
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(of,my_of_ids);
|
||||
|
||||
static int poe_info_proc_show(struct seq_file *m, void *v)
|
||||
{
|
||||
const char *type_str = "invalid";
|
||||
|
||||
switch (data->poe_type) {
|
||||
case POE_TYPE_AT:
|
||||
type_str = "AT";
|
||||
break;
|
||||
case POE_TYPE_AF:
|
||||
type_str = "AF";
|
||||
break;
|
||||
case POE_TYPE_BT:
|
||||
type_str = "BT";
|
||||
break;
|
||||
case POE_TYPE_DC:
|
||||
type_str = "DC";
|
||||
break;
|
||||
}
|
||||
|
||||
seq_printf(m, "%s\n", type_str);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void poe_tasklet_func(unsigned long data)
|
||||
{
|
||||
struct poe_irq_data *irq_data = (struct poe_irq_data *)data;
|
||||
|
||||
writel(0x3, pse_gpio_base+4);
|
||||
irq_data->poe_type = POE_TYPE_BT;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static irqreturn_t gpio_key1_irq_handler(int irq, void *dev_id)
|
||||
{
|
||||
struct poe_irq_data *data = (struct poe_irq_data *)dev_id;
|
||||
|
||||
disable_irq_nosync(data->irq);
|
||||
tasklet_schedule(&data->tasklet);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int poe_info_proc_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
return single_open(file, poe_info_proc_show, NULL);
|
||||
}
|
||||
|
||||
static const struct proc_ops poe_info_proc_fops = {
|
||||
.proc_open = poe_info_proc_open,
|
||||
.proc_read = seq_read,
|
||||
.proc_lseek = seq_lseek,
|
||||
.proc_release = single_release,
|
||||
};
|
||||
|
||||
static int gpio_key_probe(struct platform_device *dev)
|
||||
{
|
||||
int ret = 0;
|
||||
int irq = (-1);
|
||||
int val = 0;
|
||||
int gpio_id = 0;
|
||||
int gpio[GPIO_MAX] = {0}, gpio_val[GPIO_MAX] = {0};
|
||||
int num;
|
||||
char name[16];
|
||||
struct device_node *np = dev->dev.of_node;
|
||||
|
||||
if (of_property_read_u32(np, "detect-mode", &mode)) {
|
||||
pr_err("Failed to read detect mode\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
data = devm_kzalloc(&dev->dev, sizeof(struct poe_irq_data), GFP_KERNEL);
|
||||
if (!data)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (mode & INT_MODE_MASK) {
|
||||
poe_gpio_base = ioremap(0x1017004, 8);
|
||||
pse_gpio_base = ioremap(0x1026000, 8);
|
||||
|
||||
writel(0x2c1, pse_gpio_base);
|
||||
writel(0x0, pse_gpio_base+4);
|
||||
|
||||
|
||||
data->dev = &dev->dev;
|
||||
dev_set_drvdata(&dev->dev, data);
|
||||
|
||||
gpio_id = of_get_named_gpio(dev->dev.of_node, "detect_gpio", 0);
|
||||
if (gpio_id < 0)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
tasklet_init(&data->tasklet, poe_tasklet_func, (unsigned long)data);
|
||||
|
||||
ret = devm_gpio_request_one(&dev->dev, gpio_id, GPIOF_IN, "poe_judge");
|
||||
if(ret)
|
||||
{
|
||||
pr_err("GPIO23 request failed, ret:%d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
val = readl(poe_gpio_base);
|
||||
if(val == 1)
|
||||
{
|
||||
pr_info("poe type is af or bt,close pse first\n");
|
||||
data->poe_type = POE_TYPE_AF;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->poe_type = POE_TYPE_AT;
|
||||
}
|
||||
|
||||
irq = gpio_to_irq(gpio_id);
|
||||
data->irq = irq;
|
||||
|
||||
ret = devm_request_any_context_irq(&dev->dev, data->irq,
|
||||
gpio_key1_irq_handler,
|
||||
IRQF_TRIGGER_FALLING,
|
||||
"poe_judge", data);
|
||||
if (ret)
|
||||
{
|
||||
pr_err("Request irq fail %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
if (mode == DETECT_MODE1 || mode == DETECT_MODE2) {
|
||||
num = 3;
|
||||
} else {
|
||||
pr_err("Wrong poe detect mode\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
for (int i = 0; i < num; i++) {
|
||||
sprintf(name, "detect-gpio%d", i+1);
|
||||
gpio[i] = of_get_named_gpio(np, name, 0);
|
||||
ret = gpio_request(gpio[i], name);
|
||||
if (ret) {
|
||||
pr_err("Can not request gpio %d\n", i+1);
|
||||
return ret;
|
||||
}
|
||||
gpio_direction_input(gpio[i]);
|
||||
gpio_val[i] = gpio_get_value_cansleep(gpio[i]);
|
||||
}
|
||||
|
||||
if (mode == DETECT_MODE1){
|
||||
if (gpio_val[0] > 0) {
|
||||
data->poe_type = POE_TYPE_DC;
|
||||
} else if (gpio_val[1] > 0){
|
||||
if (gpio_val[2] == 0) {
|
||||
data->poe_type = POE_TYPE_AT;
|
||||
} else {
|
||||
data->poe_type = POE_TYPE_AF;
|
||||
}
|
||||
}
|
||||
}else if (mode == DETECT_MODE2){
|
||||
switch (gpio_val[0] | (gpio_val[1] << 1) | (gpio_val[2] << 2)) {
|
||||
case 3:
|
||||
data->poe_type = POE_TYPE_AT;
|
||||
break;
|
||||
case 4:
|
||||
data->poe_type = POE_TYPE_BT;
|
||||
break;
|
||||
case 7:
|
||||
data->poe_type = POE_TYPE_AF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!proc_create("poe_info", 0444, NULL, &poe_info_proc_fops)) {
|
||||
pr_err("Failed to create proc entry for poe_info\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int gpio_key_remove(struct platform_device *dev)
|
||||
{
|
||||
remove_proc_entry("poe_info", NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct platform_driver poe_judge_driver =
|
||||
{
|
||||
.driver = {
|
||||
.name = "poe_judge",
|
||||
.of_match_table = my_of_ids,
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.probe = gpio_key_probe,
|
||||
.remove = gpio_key_remove,
|
||||
};
|
||||
|
||||
module_platform_driver(poe_judge_driver);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Poe type judgment driver");
|
||||
MODULE_AUTHOR("huangyunxiang<huangyunxiang@cigtech.com>");
|
||||
@@ -236,6 +236,15 @@
|
||||
};
|
||||
};
|
||||
|
||||
poe {
|
||||
compatible = "poe-judge";
|
||||
detect-mode = <0x3>;
|
||||
detect-gpio1 = <&tlmm 25 GPIO_ACTIVE_HIGH>;
|
||||
detect-gpio2 = <&tlmm 43 GPIO_ACTIVE_HIGH>;
|
||||
detect-gpio3 = <&tlmm 29 GPIO_ACTIVE_HIGH>;
|
||||
status = "ok";
|
||||
};
|
||||
|
||||
wsi: wsi {
|
||||
id = <0>;
|
||||
num_chip = <2>;
|
||||
|
||||
@@ -298,6 +298,13 @@
|
||||
};
|
||||
};
|
||||
|
||||
poe {
|
||||
compatible = "poe-judge";
|
||||
detect-mode = <0x11>;
|
||||
detect_gpio = <&tlmm 0x17 0>;
|
||||
status = "ok";
|
||||
};
|
||||
|
||||
ess-instance {
|
||||
num_devices = <0x2>;
|
||||
|
||||
|
||||
@@ -298,6 +298,13 @@
|
||||
};
|
||||
};
|
||||
|
||||
poe {
|
||||
compatible = "poe-judge";
|
||||
detect-mode = <0x11>;
|
||||
detect_gpio = <&tlmm 0x17 0>;
|
||||
status = "ok";
|
||||
};
|
||||
|
||||
ess-instance {
|
||||
num_devices = <0x2>;
|
||||
|
||||
|
||||
@@ -234,6 +234,15 @@
|
||||
};
|
||||
};
|
||||
|
||||
poe {
|
||||
compatible = "poe-judge";
|
||||
detect-mode = <0x4>;
|
||||
detect-gpio1 = <&extgpio 0 0>;
|
||||
detect-gpio2 = <&extgpio 1 0>;
|
||||
detect-gpio3 = <&extgpio 2 0>;
|
||||
status = "ok";
|
||||
};
|
||||
|
||||
wsi: wsi {
|
||||
id = <0>;
|
||||
num_chip = <2>;
|
||||
@@ -538,7 +547,6 @@
|
||||
pinctrl-0 = <&pwm_pins>;
|
||||
pinctrl-names = "default";
|
||||
dft-pwm-status = <0>, <0>, <1>, <0>;
|
||||
poe_type_pin = <&extgpio 0 0 &extgpio 1 0 &extgpio 2 0>;
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
|
||||
@@ -13,3 +13,4 @@ packages:
|
||||
- ipq53xx
|
||||
- ftm
|
||||
- qca-ssdk-shell
|
||||
- kmod-cig-poe-judgment
|
||||
|
||||
@@ -12,3 +12,4 @@ include:
|
||||
packages:
|
||||
- ipq53xx
|
||||
- qca-ssdk-shell
|
||||
- kmod-cig-poe-judgment
|
||||
|
||||
@@ -12,3 +12,4 @@ include:
|
||||
packages:
|
||||
- ipq53xx
|
||||
- qca-ssdk-shell
|
||||
- kmod-cig-poe-judgment
|
||||
|
||||
@@ -21,3 +21,4 @@ packages:
|
||||
- kmod-gpio-pca953x
|
||||
- kmod-hwmon-tmp103
|
||||
- kmod-iio-ilps22qs
|
||||
- kmod-cig-poe-judgment
|
||||
|
||||
Reference in New Issue
Block a user