build/patch/kernel/sun8i-default/02-0013-w1_h3.patch
2016-04-13 09:25:21 +02:00

133 lines
4.4 KiB
Diff

diff -Nur a/drivers/w1/Kconfig b/drivers/w1/Kconfig
--- a/drivers/w1/Kconfig 2015-01-27 03:29:32.000000000 +0100
+++ b/drivers/w1/Kconfig 2016-01-31 00:49:00.000000000 +0100
@@ -25,6 +25,32 @@
2. Userspace commands. Includes read/write and search/alarm search commands.
3. Replies to userspace commands.
+config W1_SUNXI
+ depends on GPIO_SUNXI
+ tristate "1-wire sunxi support"
+ default n
+ --- help ---
+ This adds a way to register a platform device for 1-wire bus.
+ It introduces a new section "[w1_para]" in the FEX to configure the
+ GPIO pin number used for the bus, with the attribute named "gpio".
+ The GPIO pin must also be defined in the "[gpio_para]" section.
+
+ 1-wire device can then be accessed using the w1-gpio driver.
+
+ Example configuration :
+ [w1_para]
+ gpio = 3
+
+ [gpio_para]
+ gpio_used = 1
+ gpio_num = 3
+ ...
+ gpio_pin_3 = port:PH7<0><default><default><0>
+
+ It is also possible to configure the GPIO pin number with the
+ module paramerer "gpio". In this case, if the pin is valid,
+ it will be used instead of what is configured in the FEX script.
+
source drivers/w1/masters/Kconfig
source drivers/w1/slaves/Kconfig
diff -Nur a/drivers/w1/Makefile b/drivers/w1/Makefile
--- a/drivers/w1/Makefile 2015-01-27 03:29:32.000000000 +0100
+++ b/drivers/w1/Makefile 2016-02-11 18:52:00.000000000 +0100
@@ -3,6 +3,7 @@
#
obj-$(CONFIG_W1) += wire.o
+obj-$(CONFIG_W1_SUNXI) += w1_sunxi.o
wire-objs := w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o
obj-y += masters/ slaves/
diff -Nur a/drivers/w1/w1_sunxi.c b/drivers/w1/w1_sunxi.c
--- a/drivers/w1/w1_sunxi.c 1970-01-01 01:00:00.000000000 +0100
+++ b/drivers/w1/w1_sunxi.c 2016-01-31 00:49:00.000000000 +0100
@@ -0,0 +1,82 @@
+#include <linux/device.h>
+#include <linux/module.h>
+#include <linux/w1-gpio.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+//#include <plat/sys_config.h>
+#include <mach/sys_config.h>
+#include <mach/platform.h>
+
+static int gpio = -1;
+module_param(gpio, int, 0444);
+MODULE_PARM_DESC(gpio, "w1 gpio pin number");
+
+static struct w1_gpio_platform_data w1_gpio_pdata = {
+ .pin = -1,
+ .is_open_drain = 0,
+};
+
+static void w1_gpio_release(struct device *dev)
+{
+ printk("w1_gpio_release good !\n");
+}
+
+static struct platform_device w1_device = {
+ .name = "w1-gpio",
+ .id = -1,
+ .dev = {
+ .platform_data = &w1_gpio_pdata,
+ .release = w1_gpio_release,
+ }
+};
+
+static int __init w1_sunxi_init(void)
+{
+ int ret;
+ script_item_u val;
+ script_item_value_type_e type;
+
+ w1_gpio_pdata.pin = gpio;
+
+ if (!gpio_is_valid(w1_gpio_pdata.pin)) {
+ // *** We have to determine the pin num from fex definition
+ /*val.val = 0;
+ type = script_get_item("w1_para", "w1_used", &val);
+ if((SCIRPT_ITEM_VALUE_TYPE_INT != type) || (val.val != 1)) {
+ printk(KERN_ERR "W1: not used in fex configuration (%d, %d - %d)\n", type, id, val.val);
+ return -EINVAL;
+ }*/
+
+ val.val = gpio;
+ type = script_get_item("w1_para", "gpio", &val);
+ if(SCIRPT_ITEM_VALUE_TYPE_INT != type) {
+ printk(KERN_ERR "W1_SUNXI: invalid gpio pin in fex configuration\n");
+ return -EINVAL;
+ }
+ w1_gpio_pdata.pin = val.val;
+ if (!gpio_is_valid(w1_gpio_pdata.pin)) {
+ printk(KERN_ERR "W1_SUNXI: invalid gpio pin in fex configuration %d\n", val.val);
+ return -EINVAL;
+ }
+ }
+ ret = platform_device_register(&w1_device);
+ if (ret) {
+ printk(KERN_ERR "W1_SUNXI: error registering w1-gpio device on GPIO-%d\n", w1_gpio_pdata.pin);
+ return ret;
+ }
+ printk(KERN_INFO "W1_SUNXI: Added w1-gpio on GPIO-%d\n", w1_gpio_pdata.pin);
+ gpio_free(w1_gpio_pdata.pin);
+ return 0;
+}
+
+static void __exit w1_sunxi_exit(void)
+{
+ platform_device_unregister(&w1_device);
+}
+
+module_init(w1_sunxi_init);
+module_exit(w1_sunxi_exit);
+
+MODULE_DESCRIPTION("GPIO w1 sunxi platform device");
+MODULE_AUTHOR("Damien Nicolet <zardam@gmail.com> mod by LoBo <loboris@gmail.com");
+MODULE_LICENSE("GPL");