Meta control logic device support
cover Meta control logic device support
v1 - Support Meta control logic device driver
- Add Meta vendor prefix
- Add CLD binding document
- Add CLD driver
Delphine CC Chiu (3):
dt-bindings: vendor-prefixes: Add an entry for Meta
dt-bindings: soc: meta: Add meta cld driver bindings
misc: Add meta cld driver
.../misc/meta,control-logic-device.txt | 37 ++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443 ++++++++++++++++++ 6 files changed, 498 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/meta,control-logic-device.txt create mode 100644 drivers/misc/control-logic-device.c
Signature · 1 line
2.17.1
PATCH 1/3 dt-bindings: vendor-prefixes: Add an entry for Meta
Add "meta" entry for Meta Inc.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -793,6 +793,8 @@ patternProperties: description: Cisco Meraki, LLC "^merrii,.*": description: Merrii Technology Co., Ltd. + "^meta,.*": + description: Meta Inc. "^methode,.*": description: Methode Electronics, Inc. "^micrel,.*":
Signature · 1 line
2.17.1
Re: [PATCH v1 1/3] dt-bindings: vendor-prefixes: Add an entry for Meta
Quoted 1 line · Delphine CC Chiu
Add "meta" entry for Meta Inc.
You need to be a bit more specific. There is Meta Platforms Inc. but not Meta Inc., so you might be talking about different companies. Describe shortly the company (e.g. website, NASDAQ ticker)
Best regards,
Krzysztof
PATCH 2/3 dt-bindings: soc: meta: Add meta cld driver bindings
In reply to Delphine CC ChiuAdd a device tree bindings for Meta control logic device.
--- .../misc/meta,control-logic-device.txt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/meta,control-logic-device.txt
Documentation/devicetree/bindings/misc/meta,control-logic-device.txt new file +37 -0
@@ -0,0 +1,37 @@ +* Meta Control Logic Device(CLD) Driver + +PROPERTIES + +- compatible: + Usage: required + Type: <string-list> + Definition: must include "meta,control-logic-device-<driver version>." + For v1, the register number, name and mode can be set in dts file. + Driver exports the filesystem following the dts setting. + +- reg: + Usage: required + Definition: physical address + +- register-map: + Usage: optional + type: <string-list> + Definition: this property is an array of strings defining the names, modes + and offsets of the CLD registers. The string format is "<name>:<mode>:<offset>". + <name>: the system file name + <mode>: the system file access mode. Should be r, w or rw. + <offset>: the register offset. If it begins with 0x the number will be + parsed as a hexadecimal, if it otherwise begins with 0, it will + be parsed as an octal number. Otherwise it will be parsed as a + decimal. + +EXAMPLE + cld: cld@0f { + compatible = "meta,control-logic-device-v1"; + reg = <0x0f>; + registers-map = + "uart-selection:rw:0x00", + "led-identify:rw:0x01", + "led-critical:rw:0x02"; + }; +
Signature · 1 line
2.17.1
Re: [PATCH v1 2/3] dt-bindings: soc: meta: Add meta cld driver bindings
Quoted 1 line · Delphine CC Chiu
Add a device tree bindings for Meta control logic device.
Subject: drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings.
Subject: Drop "driver"
Documentation/devicetree/bindings/misc/meta,control-logic-device.txt
Quoted 12 lines
Signed-off-by Delphine CC Chiu <[email protected]>--- .../misc/meta,control-logic-device.txt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/misc/meta,control-logic-device.txtDocumentation/devicetree/bindings/misc/meta,control-logic-device.txt new file +0
-0
New bindings only in DT schema format. Start Documentation/devicetree/bindings/writing-schema.rst, example-schema.yaml and other docs.
Best regards,
Krzysztof
RE: [PATCH v1 2/3] dt-bindings: soc: meta: Add meta cld driver bindings
Hi Krzysztof,
Thanks for your comment.
Quoted 16 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Tuesday, January 17, 2023 6:50 PM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>; [email protected]; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>
Cc: [email protected]; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; Stanislav Jakubek <[email protected]>; Daniel Palmer <[email protected]>; Linus Walleij <[email protected]>; Samuel Holland <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 2/3] dt-bindings: soc: meta: Add meta cld driver bindings
Quoted 8 lines
Security Reminder: Please be aware that this email is sent by an external
sender.Quoted 1 line · Delphine CC Chiu
Add a device tree bindings for Meta control logic device.
Subject: drop second/last, redundant "bindings". The "dt-bindings" prefix is already stating that these are bindings.
We will remove the bindings from the subject.
Quoted 2 lines
Subject: Drop "driver"
We will revise the subject.
Quoted 9 lines
Quoted 9 lines
Signed-off-by Delphine CC Chiu <[email protected]>--- .../misc/meta,control-logic-device.txt | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644
Documentation/devicetree/bindings/misc/meta,control-logic-device.txt
Quoted 12 lines
Documentation/devicetree/bindings/misc/meta,control-logic-device
Quoted 8 lines
diff --git
a/Documentation/devicetree/bindings/misc/meta,control-logic-device.txtb/Documentation/devicetree/bindings/misc/meta,control-logic-device.txtnew file mode 100644
index 000000000000..e966368e2fd6Documentation/devicetree/bindings/misc/meta,control-logic-device new file +1
-0+++ .txtNew bindings only in DT schema format. Start
Documentation/devicetree/bindings/writing-schema.rst,example-schema.yamland other docs.
We will rewrite the binding document following the schema.
Quoted 5 lines
Best regards,
Krzysztof
Thanks,
Delphine
PATCH 3/3 misc: Add meta cld driver
In reply to Delphine CC ChiuAdd support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
--- MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443 ++++++++++++++++++++++++++++ 4 files changed, 459 insertions(+) create mode 100644 drivers/misc/control-logic-device.c
MAINTAINERS +6 -0
@@ -13388,6 +13388,12 @@ T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/amlogic,gx-vdec.yaml F: drivers/staging/media/meson/vdec/ +META CPLD DRIVER +M: Delphine CC Chiu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/misc/meta,control-logic-device.txt + METHODE UDPU SUPPORT M: Vladimir Vid <[email protected]> S: Maintained
drivers/misc/Kconfig +9 -0
@@ -496,6 +496,15 @@ config VCPU_STALL_DETECTOR If you do not intend to run this kernel as a guest, say N. +config CONTROL_LOGIC_DEVICE + bool "Meta Control Logic Device Driver" + depends on I2C && REGMAP + help + Say yes here to add support for the Meta CLD device driver. The dirver + is used to monitor CLD register value and notify the application if + value is changed. Application also can access the CLD register value + through this driver. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
@@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o obj-$(CONFIG_OPEN_DICE) += open-dice.o obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o +obj-$(CONFIG_CONTROL_LOGIC_DEVICE) += control-logic-device.o
drivers/misc/control-logic-device.c new file +443 -0
443 lines not on this page · raw message
Signature · 1 line
2.17.1
Greg Kroah-Hartman
maintainerRe: [PATCH v1 3/3] misc: Add meta cld driver
Quoted 9 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Quoted 7 lines
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>--- MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443 ++++++++++++++++++++++++++++
That is a very generic name for a very specific driver. Please make it more hardware-specific.
Also, you add a bunch of undocumented sysfs files here, which require a Documentation/ABI/ entries so that we can review the code to verify it does what you all think it does.
And finally, why is this needed to be a kernel driver at all? Why can't you control this all through the userspace i2c api?
One review comment:
drivers/misc/control-logic-device.c line 414
Quoted 11 lines
drivers/misc/control-logic-device.c new file +11
-0+static int cld_remove (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct cld_client *cld =dev_get_drvdata (dev); + +if (cld->task) { +kthread_stop (cld->task); + cld->task =NULL ; + } + +devm_kfree (dev, cld);
Whenever you see this line in code, it's almost always a huge red flag that someone is not using the devm_* api properly. I think that is most certainly the case here.
thanks,
greg k-h
RE: [PATCH v1 3/3] misc: Add meta cld driver
Hi Greg,
Thanks for your comment!
Quoted 35 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Tuesday, January 17, 2023 6:15 PM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>
Cc: [email protected]; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; [email protected]; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Stanislav Jakubek <[email protected]>; Linus Walleij <[email protected]>; Samuel Holland <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 3/3] misc: Add meta cld driverSecurity Reminder: Please be aware that this email is sent by an external
sender.Quoted 9 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Quoted 8 lines
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>--- MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443++++++++++++++++++++++++++++
Quoted 2 lines
That is a very generic name for a very specific driver. Please make it more hardware-specific.
In server project, there is a component (control-logic-device). This component manages the server status including whole system power sequence, status and other devices presence status. And baseboard management controller (BMC) on server can acquire the information from CLD device through I2C. Currently, our customer plan to follow the spec to design the computing server.
We would like to change the naming from CLD to "compute CPLD".
Do you have any suggestion?
Quoted 4 lines
Also, you add a bunch of undocumented sysfs files here, which require a
Documentation/ABI/entries so that we can review the code to verify it does what you all think it does.
We will add the document in Documentation/ABI/testing folder.
Quoted 3 lines
And finally, why is this needed to be a kernel driver at all? Why can't you control this all through the userspace i2c api?
After discussing with our customer, they prefer the userspace access the physical device through driver not I2C API. There is an example on the OpenBMC Gerrit.
https://gerrit.openbmc.org/c/openbmc/phosphor-buttons/+/60807
Quoted 17 lines
One review comment:
drivers/misc/control-logic-device.c line 414
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+static int cld_remove (struct i2c_client *client) { +struct device *dev = &client->dev; +struct cld_client *cld =dev_get_drvdata (dev); + +if (cld->task) { +kthread_stop (cld->task); + cld->task =NULL ; + } + +devm_kfree (dev, cld);Whenever you see this line in code, it's almost always a huge red flag that someone is not using the devm_* api properly. I think that is most certainly the case here.
Do you mean the dev_free function is no need in this remove function?
Quoted 4 lines
thanks,
greg k-h
Thanks,
Delphine
Greg Kroah-Hartman
maintainerRe: [PATCH v1 3/3] misc: Add meta cld driver
Quoted 39 lines · Delphine_CC_Chiu/WYHQ/Wiwynn
Hi Greg,
Thanks for your comment!
Quoted 35 lines
-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Tuesday, January 17, 2023 6:15 PM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>
Cc: [email protected]; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; [email protected]; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Stanislav Jakubek <[email protected]>; Linus Walleij <[email protected]>; Samuel Holland <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 3/3] misc: Add meta cld driverSecurity Reminder: Please be aware that this email is sent by an external
sender.Quoted 17 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>--- MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443++++++++++++++++++++++++++++
Quoted 7 lines
Quoted 2 lines
That is a very generic name for a very specific driver. Please make it more hardware-specific.
In server project, there is a component (control-logic-device). This component manages the server status including whole system power sequence, status and other devices presence status. And baseboard management controller (BMC) on server can acquire the information from CLD device through I2C. Currently, our customer plan to follow the spec to design the computing server.
We would like to change the naming from CLD to "compute CPLD".
Do you have any suggestion?
Make it something hardware/vendor specific please. As is, this is very generic. Remember, this is a name you will be using to refer to for the next 20+ years.
Quoted 7 lines
Quoted 3 lines
Also, you add a bunch of undocumented sysfs files here, which require a
Documentation/ABI/entries so that we can review the code to verify it does what you all think it does.We will add the document in
Documentation/ABI/testingfolder.Quoted 1 line
Quoted 6 lines
Quoted 2 lines
And finally, why is this needed to be a kernel driver at all? Why can't you control this all through the userspace i2c api?
After discussing with our customer, they prefer the userspace access the physical device through driver not I2C API. There is an example on the OpenBMC Gerrit.
https://gerrit.openbmc.org/c/openbmc/phosphor-buttons/+/60807
I do not understand, if functionalty can be done in userspace, it should be done there, UNLESS you have a generic way of handling multiple hardware devices as the same type (i.e. keyboard, sensor, etc.) There does not seem to be any generic interface here, so again, why can't you just do it all in userspace? What is forcing a kernel driver for this?
Quoted 17 lines
Quoted 16 lines
One review comment:
drivers/misc/control-logic-device.c line 414
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+static int cld_remove (struct i2c_client *client) { +struct device *dev = &client->dev; +struct cld_client *cld =dev_get_drvdata (dev); + +if (cld->task) { +kthread_stop (cld->task); + cld->task =NULL ; + } + +devm_kfree (dev, cld);Whenever you see this line in code, it's almost always a huge red flag that someone is not using the devm_* api properly. I think that is most certainly the case here.
Quoted 1 line
Do you mean the
dev_freefunction is no need in this remove function?
Why do you think it is needed here? If it is needed, please document it with a comment explaining why this is required as it is not how the api is designed to be used at all.
thanks,
greg k-h
Re: [PATCH v1 3/3] misc: Add meta cld driver
In reply to Delphine CC ChiuQuoted 24 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>--- MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443 ++++++++++++++++++++++++++++ 4 files changed, 459 insertions(+) create mode 100644 drivers/misc/control-logic-device.cMAINTAINERS +0
-0
MAINTAINERS T: git git://linuxtv.org/media_tree.git · line 13395
Quoted 8 lines
MAINTAINERS +5
-0@@ -13388,6 +13388,12 @@ T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/amlogic,gx-vdec.yaml F: drivers/staging/media/meson/vdec/ +META CPLD DRIVER +M: Delphine CC Chiu <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/misc/meta,control-logic-device.txt
Missing entries for driver code.
Quoted 9 lines
MAINTAINERS +1
-0+ METHODE UDPU SUPPORT M: Vladimir Vid <[email protected]> S: Maintaineddrivers/misc/Kconfig +0
-0
drivers/misc/Kconfig config VCPU_STALL_DETECTOR · line 500
Quoted 5 lines
drivers/misc/Kconfig +2
-0@@ -496,6 +496,15 @@ config VCPU_STALL_DETECTOR If you do not intend to run this kernel as a guest, say N. +config CONTROL_LOGIC_DEVICE + bool "Meta Control Logic Device Driver"
Too generic...
Quoted 15 lines
drivers/misc/Kconfig +7
-0+ depends on I2C && REGMAP + help + Say yes here to add support for the Meta CLD device driver. The dirver + is used to monitor CLD register value and notify the application if + value is changed. Application also can access the CLD register value + through this driver. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"drivers/misc/Makefile +0
-0
drivers/misc/Makefile obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o · line 65
Quoted 4 lines
drivers/misc/Makefile +1
-0@@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o obj-$(CONFIG_OPEN_DICE) += open-dice.o obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o +obj-$(CONFIG_CONTROL_LOGIC_DEVICE) += control-logic-device.o
Does not look like ordered by name.
drivers/misc/control-logic-device.c line 6
Quoted 12 lines
drivers/misc/control-logic-device.c new file +6
-0@@ -0,0 +1,443 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2022 Meta Inc. +*/ + +#include <linux/module.h>
Don't prepend with spaces. Check the code for such trivial style issues first.
Quoted 334 lines
drivers/misc/control-logic-device.c new file +334
-0+#include <linux/i2c.h> +#include <linux/regmap.h> +#include <linux/sysfs.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/stddef.h> +#include <linux/kthread.h> + +#define CLD_LABEL_LEN 64/* label = "name:mode:offset" */ +#define to_cld_reg (x) container_of(x, struct cld_data, bin) + +struct cld_register_info { +const char *name; +umode_t mode; +u8 reg; +u8 value; +}; + +struct cld_data { +struct list_head list; +struct bin_attribute bin; +struct kernfs_node *kn; +struct cld_register_info info; +}; + +struct cld_client { +struct bin_attribute new_register_bin; +struct bin_attribute delet_register_bin; +struct regmap *regmap; +struct device *dev; +struct cld_data *data; +struct task_struct *task; +size_t num_attributes; +}; + +struct meta_cld_of_ops { +int (*load_registers)(struct cld_client *cld); +}; + +static struct regmap_config cld_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .cache_type =REGCACHE_NONE , +}; + +static ssize_t cld_register_read (struct file *flip,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t pos,size_t count) +{ +int ret; +unsigned int value; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_data *data =to_cld_reg (attr); + + ret =regmap_read (cld->regmap, data->info.reg, &value); +if (ret !=0 ) +return ret; + +if ((data->info.mode &0400 ) ==0400 ) + data->info.value = value; + +snprintf (buf,sizeof (value),"%d\n" , value); + +return strlen (buf); +} + +static ssize_t cld_register_write (struct file *flip,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t pos,size_t count) +{ +int ret; +unsigned long val; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_data *data =to_cld_reg (attr); + + ret =kstrtoul (buf,0 , &val); +if (ret) + goto out; + +if (val >=BIT (8 )) { + ret = -EINVAL ; + goto out; + } + + ret =regmap_write (cld->regmap, data->info.reg, val); +if (ret) + goto out; + +out: +return ret ? ret :strlen (buf); +} + +static int cld_bin_register (struct cld_register_info info, +struct cld_client *cld) +{ +int ret; +struct cld_data *data, *pos; +struct bin_attribute *bin; +size_t length; + +list_for_each_entry (pos, &cld->data->list, list) { + length = (strlen (info.name) >strlen (pos->info.name)) ? +strlen (info.name):strlen (pos->info.name); +if (!strncasecmp (info.name, pos->info.name, length)) +return -EEXIST ; + } + + data =devm_kzalloc (cld->dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + bin = &data->bin; + data->info = info; + +sysfs_bin_attr_init (bin); + bin->attr.name =kstrdup (info.name,GFP_KERNEL ); +if (!bin->attr.name) +return -EINVAL ; + bin->attr.mode = info.mode; + bin->read = cld_register_read; + bin->write = cld_register_write; + bin->size =1 ; + ret =sysfs_create_bin_file (&cld->dev->kobj, bin); +if (ret) { +dev_err (cld->dev,"%s: failed to create file: %d\n" , + info.name, ret); + goto out; + } + + data->kn =kernfs_find_and_get (cld->dev->kobj.sd, bin->attr.name); +if (!data->kn) { +sysfs_remove_bin_file (&cld->dev->kobj, bin); + ret = -EFAULT ; + goto out; + } + +list_add_tail (&data->list, &cld->data->list); + ++cld->num_attributes; +out: +return ret; +} + +static int cld_bin_unregister (struct cld_register_info info, +struct cld_client *cld) +{ +size_t length; +struct cld_data *pos; + +list_for_each_entry (pos, &cld->data->list, list) { + length = (strlen (info.name) >strlen (pos->info.name)) ? +strlen (info.name):strlen (pos->info.name); +if ((!strncasecmp (info.name, pos->info.name, length)) && + (info.mode == pos->info.mode) && + (info.reg == pos->info.reg)) { +kernfs_put (pos->kn); +sysfs_remove_bin_file (&cld->dev->kobj, + &pos->bin); +list_del (&pos->list); +devm_kfree (cld->dev, pos); + --cld->num_attributes; +return 0 ; + } + } + +dev_err (cld->dev,"%s: cannot match cld data\n" , info.name); +return -EINVAL ; +} + +static int cld_parse_label (char *label,struct cld_register_info *info) +{ +char name[CLD_LABEL_LEN ] = {0 }; +char *mode_str, *reg_str; +int rc, i; +unsigned long reg; +umode_t mode; +size_t length; +struct { +char *mode; +int value; + } options[] = { + {"rw" ,0600 }, + {"r" ,0400 }, + {"w" ,0200 }, + }; + +strncpy (name, label,CLD_LABEL_LEN ); + + mode_str =strchr (name,':' ); +if (!mode_str) +return -EINVAL ; + *mode_str++ ='\0' ; + + reg_str =strchr (mode_str,':' ); +if (!reg_str) +return -EINVAL ; + *reg_str++ ='\0' ; + +if ((*name =='\0' ) || (*mode_str =='\0' ) || (*reg_str =='\0' )) +return -EINVAL ; + +for (i =0 ; i <ARRAY_SIZE (options); i++) { + length = (strlen (options[i].mode) >strlen (mode_str)) ? +strlen (options[i].mode):strlen (mode_str); +if (strncasecmp (mode_str, options[i].mode, length) ==0 ) { + rc =kstrtoul (reg_str,0 , ®); +if (rc) +return -EINVAL ; + mode = options[i].value; +break ; + } + } +if ((i >=ARRAY_SIZE (options)) || (reg >=BIT (8 ))) +return -EINVAL ; + + info->name =kstrdup (name,GFP_KERNEL ); +if (!info->name) +return -EINVAL ; + info->reg = reg; + info->mode = mode; +return 0 ; +} + +static int cld_load_registers (struct cld_client *cld,const char *property) +{ +const char *label; +int count, ret, i; +struct cld_register_info info; +struct device *dev = cld->dev; + + count =of_property_count_strings (dev->of_node, property); +if (count <=0 ) +return -EINVAL ; + +for (i =0 ; i < count; i++) { + ret =of_property_read_string_index (dev->of_node, property, i, + &label); +if (ret) { +dev_err (dev,": failed to get label for index %d\n" , + i); +continue ; + } + + ret =cld_parse_label ((char *)label, &info); +if (ret) { +dev_err (cld->dev,"%s: failed to parse label\n" , + label); +continue ; + } +cld_bin_register (info, cld); + } +return (count == cld->num_attributes) ?0 : (-EINVAL ); +} + +static int meta_cld_of_v1_load_registers (struct cld_client *cld) +{ +int ret; + + ret =cld_load_registers (cld,"registers-map" ); +if (ret) +dev_dbg (cld->dev,"failed to load registers\n" ); + +return 0 ; +} + +static ssize_t cld_sysfs_new_register (struct file *filp,struct kobject *kobj, +struct bin_attribute *attr, +char *buf,loff_t pos,size_t count) +{ +int ret; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_register_info info; + + ret =cld_parse_label (buf, &info); +if (ret) { +dev_err (cld->dev,"failed to parse label\n" ); + goto out; + } + ret =cld_bin_register (info, cld); + +out: +return (!ret) ? count : ret; +} + +static ssize_t cld_sysfs_delete_register (struct file *filp, +struct kobject *kobj, +struct bin_attribute *attr, +char *buf,loff_t pos,size_t count) +{ +int ret; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_register_info info; + + ret =cld_parse_label (buf, &info); +if (ret) { +dev_err (cld->dev,"failed to parse label\n" ); + goto out; + } + + ret =cld_bin_unregister (info, cld); + +out: +return (!ret) ? count : ret; +} + +static int cld_monitor_thread (void *client) +{ +struct cld_client *cld = client; +unsigned int value; +int ret; +struct cld_data *pos; + +while (!kthread_should_stop ()) { +list_for_each_entry (pos, &cld->data->list, list) { +if ((pos->info.mode &0400 ) ==0400 ) { + ret =regmap_read (cld->regmap, pos->info.reg, + &value); +if (ret) +continue ; +if (pos->info.value != value) { + pos->info.value = value; +kernfs_notify (pos->kn); + } + } + } +msleep (50 ); + } +return 0 ; +} + +static int cld_probe(struct i2c_client *client,
drivers/misc/control-logic-device.c line 350
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+ const struct i2c_device_id *id) +{ +int ret =0 ; +const struct meta_cld_of_ops *ops; +struct device *dev = &client->dev; +struct cld_client *cld; + + cld =devm_kzalloc (dev,sizeof (*cld),GFP_KERNEL ); +if (!cld) { + ret = -ENOMEM ;
return
drivers/misc/control-logic-device.c line 357
Quoted 7 lines
drivers/misc/control-logic-device.c new file +7
-0+ goto out; + } + + cld->dev = dev; + cld->num_attributes =0 ; + cld->regmap =devm_regmap_init_i2c (client, &cld_regmap_config); + cld->data = devm_kzalloc(cld->dev, sizeof(struct cld_data),
sizeof(*)
drivers/misc/control-logic-device.c line 360
Quoted 3 lines
drivers/misc/control-logic-device.c new file +3
-0+ GFP_KERNEL); +if (!cld->data) { + ret = -ENOMEM ;
return
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+ goto out; + } + +INIT_LIST_HEAD (&cld->data->list); + +sysfs_bin_attr_init (&cld->new_register_bin); + cld->new_register_bin.attr.name ="new_register" ; + cld->new_register_bin.attr.mode =0200 ; + cld->new_register_bin.write = cld_sysfs_new_register; + ret =sysfs_create_bin_file (&dev->kobj, &cld->new_register_bin);
drivers/misc/control-logic-device.c line 380
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+if (ret) + goto out; + +sysfs_bin_attr_init (&cld->delet_register_bin); + cld->delet_register_bin.attr.name ="delete_register" ; + cld->delet_register_bin.attr.mode =0200 ; + cld->delet_register_bin.write = cld_sysfs_delete_register; + ret =sysfs_create_bin_file (&dev->kobj, &cld->delet_register_bin); +if (ret) + goto out;
return
drivers/misc/control-logic-device.c line 384
Quoted 4 lines
drivers/misc/control-logic-device.c new file +4
-0+ + ops =of_device_get_match_data (cld->dev); +if (!ops) { + ret = -EINVAL ;
return
drivers/misc/control-logic-device.c line 391
Quoted 7 lines
drivers/misc/control-logic-device.c new file +7
-0+ goto out; + } + + ret = ops->load_registers (cld); + + cld->task =kthread_run (cld_monitor_thread, (void *)cld, +"register_monitor" );
Why do you need the thread? What do you monitor? All this should be explained and documented.
drivers/misc/control-logic-device.c line 393
Quoted 2 lines
drivers/misc/control-logic-device.c new file +2
-0+if (IS_ERR (cld->task)) { + ret =PTR_ERR (cld->task);
return
drivers/misc/control-logic-device.c line 394
Quoted 1 line
drivers/misc/control-logic-device.c new file +1
-0+ cld->task =NULL ;
Drop
drivers/misc/control-logic-device.c line 398
Quoted 4 lines
drivers/misc/control-logic-device.c new file +4
-0+ goto out; + } + +dev_set_drvdata (dev, cld);
This should happen before starting thread.
Quoted 14 lines
drivers/misc/control-logic-device.c new file +14
-0+ +out: +return ret; +} + +static int cld_remove (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct cld_client *cld =dev_get_drvdata (dev); + +if (cld->task) { +kthread_stop (cld->task); + cld->task =NULL ; + }
drivers/misc/control-logic-device.c line 422
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+ +devm_kfree (dev, cld); +return 0 ; +} + +static const struct meta_cld_of_ops of_v1_ops = { + .load_registers = meta_cld_of_v1_load_registers, +}; + +static const struct of_device_id cld_of_match[] = {
This would warn now. Drop of_match_ptr.
drivers/misc/control-logic-device.c line 434
Quoted 12 lines
drivers/misc/control-logic-device.c new file +12
-0+ { + .compatible = "meta,control-logic-device-v1", + .data = &of_v1_ops, + }, + {} +}; + +MODULE_DEVICE_TABLE(of, cld_of_match) + +static struct i2c_driver cld = { + .driver = { .name ="cld-driver" , + .of_match_table =of_match_ptr (cld_of_match) },
Blank line before }
drivers/misc/control-logic-device.c line 443
Quoted 9 lines
drivers/misc/control-logic-device.c new file +9
-0+ .probe = cld_probe, + .remove = cld_remove, +}; + +module_i2c_driver (cld); + +MODULE_AUTHOR ("Ren Chen <[email protected]>" ); +MODULE_DESCRIPTION ("Meta control logic device driver" ); +MODULE_LICENSE ("GPL" );
Best regards,
Krzysztof
RE: [PATCH v1 3/3] misc: Add meta cld driver
Hi Krzysztof,
Thanks for your review comment.
Quoted 46 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Tuesday, January 17, 2023 6:55 PM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>; [email protected]; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>
Cc: [email protected]; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Stanislav Jakubek <[email protected]>; Linus Walleij <[email protected]>; Samuel Holland <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 3/3] misc: Add meta cld driverSecurity Reminder: Please be aware that this email is sent by an external
sender.Quoted 28 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>--- MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443 ++++++++++++++++++++++++++++ 4 files changed, 459 insertions(+) create mode 100644 drivers/misc/control-logic-device.cMAINTAINERS index renamed from MAINTAINERS +0
-0
7483853880b6..46e250a2c334100644MAINTAINERS +0
-0@@ -13388,6 +13388,12 @@ T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/amlogic,gx-vdec.yaml F: drivers/staging/media/meson/vdec/
Quoted 8 lines
MAINTAINERS T: git git://linuxtv.org/media_tree.git
Quoted 5 lines
MAINTAINERS +5
-0+META CPLD DRIVER +M: Delphine CC Chiu <[email protected]> +L: [email protected] +S: Maintained +F:
Documentation/devicetree/bindings/misc/meta,control-logic-device.txtMissing entries for driver code.
We saw there are entries defined in MAINTAINERS file(M, R, L, S, W, Q, B, C, P, T, F, X, N, K). Could you guide us which entries are must to have?
Quoted 37 lines
Quoted 10 lines
MAINTAINERS +1
-0+ METHODE UDPU SUPPORT M: Vladimir Vid <[email protected]> S: Maintaineddrivers/misc/Kconfig index renamed from drivers/misc/Kconfig +0
-0
358ad56f6524..21d3bf820438100644drivers/misc/Kconfig config VCPU_STALL_DETECTOR · line 500
Quoted 5 lines
drivers/misc/Kconfig +2
-0@@ -496,6 +496,15 @@ config VCPU_STALL_DETECTOR If you do not intend to run this kernel as a guest, say N. +config CONTROL_LOGIC_DEVICE + bool "Meta Control Logic Device Driver"Too generic...
drivers/misc/Kconfig config VCPU_STALL_DETECTOR
Quoted 3 lines
drivers/misc/Kconfig +3
-0+ depends on I2C && REGMAP + help + Say yes here to add support for the Meta CLD device driver. Thedirver
drivers/misc/Kconfig config VCPU_STALL_DETECTOR · line 504
Quoted 1 line
drivers/misc/Kconfig +1
-0+ is used to monitor CLD register value and notify the applicationif
drivers/misc/Kconfig config VCPU_STALL_DETECTOR · line 505
Quoted 1 line
drivers/misc/Kconfig +1
-0+ value is changed. Application also can access the CLD registervalue
drivers/misc/Makefile obj-$(CONFIG_HI6421V600_IRQ) +=
Quoted 10 lines
drivers/misc/Kconfig +2
-0+ through this driver. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig"drivers/misc/Makefile index renamed from drivers/misc/Makefile +0
-0
ac9b3e757ba1..6fcdd575a143100644drivers/misc/Makefile +0
-0@@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) +=hi6421v600-irq.o
Quoted 6 lines
drivers/misc/Makefile obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o · line 65
Quoted 4 lines
drivers/misc/Makefile +1
-0obj-$(CONFIG_OPEN_DICE) += open-dice.o obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o +obj-$(CONFIG_CONTROL_LOGIC_DEVICE) += control-logic-device.oDoes not look like ordered by name.
The file look like without ordered by name so we added the configuration in the tail. Do we need to order the Makefile?
Quoted 16 lines
Quoted 8 lines
drivers/misc/control-logic-device.c new file +0
-0drivers/misc/control-logic-device.c line 6
Quoted 6 lines
drivers/misc/control-logic-device.c new file +6
-0@@ -0,0 +1,443 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2022 Meta Inc. +*/ + +#include <linux/module.h> Don't prepend with spaces. Check the code for such trivial style issues first.
We will revise this.
Quoted 332 lines
Quoted 223 lines
drivers/misc/control-logic-device.c new file +222
-0+#include <linux/i2c.h> +#include <linux/regmap.h> +#include <linux/sysfs.h> +#include <linux/of.h> +#include <linux/of_device.h> +#include <linux/stddef.h> +#include <linux/kthread.h> + +#define CLD_LABEL_LEN 64/* label = "name:mode:offset" */ #define +to_cld_reg (x) container_of(x, struct cld_data, bin) + +struct cld_register_info { +const char *name; +umode_t mode; +u8 reg; +u8 value; +}; + +struct cld_data { +struct list_head list; +struct bin_attribute bin; +struct kernfs_node *kn; +struct cld_register_info info; +}; + +struct cld_client { +struct bin_attribute new_register_bin; +struct bin_attribute delet_register_bin; +struct regmap *regmap; +struct device *dev; +struct cld_data *data; +struct task_struct *task; +size_t num_attributes; +}; + +struct meta_cld_of_ops { +int (*load_registers)(struct cld_client *cld); }; + +static struct regmap_config cld_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + .cache_type =REGCACHE_NONE , +}; + +static ssize_t cld_register_read (struct file *flip,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t pos,size_t count) { +int ret; +unsigned int value; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_data *data =to_cld_reg (attr); + + ret =regmap_read (cld->regmap, data->info.reg, &value); +if (ret !=0 ) +return ret; + +if ((data->info.mode &0400 ) ==0400 ) + data->info.value = value; + +snprintf (buf,sizeof (value),"%d\n" , value); + +return strlen (buf); +} + +static ssize_t cld_register_write (struct file *flip,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t pos,size_t count) { +int ret; +unsigned long val; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_data *data =to_cld_reg (attr); + + ret =kstrtoul (buf,0 , &val); +if (ret) + goto out; + +if (val >=BIT (8 )) { + ret = -EINVAL ; + goto out; + } + + ret =regmap_write (cld->regmap, data->info.reg, val); +if (ret) + goto out; + +out: +return ret ? ret :strlen (buf); +} + +static int cld_bin_register (struct cld_register_info info, +struct cld_client *cld) { +int ret; +struct cld_data *data, *pos; +struct bin_attribute *bin; +size_t length; + +list_for_each_entry (pos, &cld->data->list, list) { + length = (strlen (info.name) >strlen (pos->info.name)) ? +strlen (info.name):strlen (pos->info.name); +if (!strncasecmp (info.name, pos->info.name, length)) +return -EEXIST ; + } + + data =devm_kzalloc (cld->dev,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + + bin = &data->bin; + data->info = info; + +sysfs_bin_attr_init (bin); + bin->attr.name =kstrdup (info.name,GFP_KERNEL ); +if (!bin->attr.name) +return -EINVAL ; + bin->attr.mode = info.mode; + bin->read = cld_register_read; + bin->write = cld_register_write; + bin->size =1 ; + ret =sysfs_create_bin_file (&cld->dev->kobj, bin); +if (ret) { +dev_err (cld->dev,"%s: failed to create file: %d\n" , + info.name, ret); + goto out; + } + + data->kn =kernfs_find_and_get (cld->dev->kobj.sd, bin->attr.name); +if (!data->kn) { +sysfs_remove_bin_file (&cld->dev->kobj, bin); + ret = -EFAULT ; + goto out; + } + +list_add_tail (&data->list, &cld->data->list); + ++cld->num_attributes; +out: +return ret; +} + +static int cld_bin_unregister (struct cld_register_info info, +struct cld_client *cld) { +size_t length; +struct cld_data *pos; + +list_for_each_entry (pos, &cld->data->list, list) { + length = (strlen (info.name) >strlen (pos->info.name)) ? +strlen (info.name):strlen (pos->info.name); +if ((!strncasecmp (info.name, pos->info.name, length)) && + (info.mode == pos->info.mode) && + (info.reg == pos->info.reg)) { +kernfs_put (pos->kn); +sysfs_remove_bin_file (&cld->dev->kobj, + &pos->bin); +list_del (&pos->list); +devm_kfree (cld->dev, pos); + --cld->num_attributes; +return 0 ; + } + } + +dev_err (cld->dev,"%s: cannot match cld data\n" , info.name); +return -EINVAL ; +} + +static int cld_parse_label (char *label,struct cld_register_info +*info) { +char name[CLD_LABEL_LEN ] = {0 }; +char *mode_str, *reg_str; +int rc, i; +unsigned long reg; +umode_t mode; +size_t length; +struct { +char *mode; +int value; + } options[] = { + {"rw" ,0600 }, + {"r" ,0400 }, + {"w" ,0200 }, + }; + +strncpy (name, label,CLD_LABEL_LEN ); + + mode_str =strchr (name,':' ); +if (!mode_str) +return -EINVAL ; + *mode_str++ ='\0' ; + + reg_str =strchr (mode_str,':' ); +if (!reg_str) +return -EINVAL ; + *reg_str++ ='\0' ; + +if ((*name =='\0' ) || (*mode_str =='\0' ) || (*reg_str =='\0' )) +return -EINVAL ; + +for (i =0 ; i <ARRAY_SIZE (options); i++) { + length = (strlen (options[i].mode) >strlen (mode_str)) ? +strlen (options[i].mode):strlen (mode_str); +if (strncasecmp (mode_str, options[i].mode, length) ==0 ) { + rc =kstrtoul (reg_str,0 , ®); +if (rc) +return -EINVAL ; + mode = options[i].value; +break ; + } + } +if ((i >=ARRAY_SIZE (options)) || (reg >=BIT (8 ))) +return -EINVAL ; + + info->name =kstrdup (name,GFP_KERNEL ); +if (!info->name) +return -EINVAL ; + info->reg = reg; + info->mode = mode; +return 0 ; +} + +static int cld_load_registers (struct cld_client *cld,const char +*property) { +const char *label;drivers/misc/control-logic-device.c
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+int count, ret, i; +struct cld_register_info info; +struct device *dev = cld->dev; + + count =of_property_count_strings (dev->of_node, property); +if (count <=0 ) +return -EINVAL ; + +for (i =0 ; i < count; i++) { + ret = of_property_read_string_index(dev->of_node,property, i,
Quoted 69 lines
drivers/misc/control-logic-device.c new file +69
-0+ &label); +if (ret) { +dev_err (dev,": failed to get label for index %d\n" , + i); +continue ; + } + + ret =cld_parse_label ((char *)label, &info); +if (ret) { +dev_err (cld->dev,"%s: failed to parse label\n" , + label); +continue ; + } +cld_bin_register (info, cld); + } +return (count == cld->num_attributes) ?0 : (-EINVAL ); } + +static int meta_cld_of_v1_load_registers (struct cld_client *cld) { +int ret; + + ret =cld_load_registers (cld,"registers-map" ); +if (ret) +dev_dbg (cld->dev,"failed to load registers\n" ); + +return 0 ; +} + +static ssize_t cld_sysfs_new_register (struct file *filp,struct kobject *kobj, +struct bin_attribute *attr, +char *buf,loff_t pos,size_t +count) { +int ret; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_register_info info; + + ret =cld_parse_label (buf, &info); +if (ret) { +dev_err (cld->dev,"failed to parse label\n" ); + goto out; + } + ret =cld_bin_register (info, cld); + +out: +return (!ret) ? count : ret; +} + +static ssize_t cld_sysfs_delete_register (struct file *filp, +struct kobject *kobj, +struct bin_attribute *attr, +char *buf,loff_t pos,size_t +count) { +int ret; +struct device *dev =kobj_to_dev (kobj); +struct cld_client *cld =dev_get_drvdata (dev); +struct cld_register_info info; + + ret =cld_parse_label (buf, &info); +if (ret) { +dev_err (cld->dev,"failed to parse label\n" ); + goto out; + } + + ret =cld_bin_unregister (info, cld); + +out: +return (!ret) ? count : ret; +} +drivers/misc/control-logic-device.c
Quoted 10 lines
drivers/misc/control-logic-device.c new file +10
-0+static int cld_monitor_thread (void *client) { +struct cld_client *cld = client; +unsigned int value; +int ret; +struct cld_data *pos; + +while (!kthread_should_stop ()) { +list_for_each_entry (pos, &cld->data->list, list) { +if ((pos->info.mode &0400 ) ==0400 ) { + ret = regmap_read(cld->regmap,
pos->info.reg,Quoted 18 lines
drivers/misc/control-logic-device.c new file +18
-0+ &value); +if (ret) +continue ; +if (pos->info.value != value) { + pos->info.value = value; +kernfs_notify (pos->kn); + } + } + } +msleep (50 ); + } +return 0 ; +} + +static int cld_probe (struct i2c_client *client, +const struct i2c_device_id *id) { +int ret =0 ; +const struct meta_cld_of_ops *ops;
Quoted 8 lines
drivers/misc/control-logic-device.c line 350
Quoted 6 lines
drivers/misc/control-logic-device.c new file +6
-0+struct device *dev = &client->dev; +struct cld_client *cld; + + cld =devm_kzalloc (dev,sizeof (*cld),GFP_KERNEL ); +if (!cld) { + ret = -ENOMEM ;return
We will revise this.
Quoted 9 lines
drivers/misc/control-logic-device.c line 357
Quoted 8 lines
drivers/misc/control-logic-device.c new file +7
-0+ goto out; + } + + cld->dev = dev; + cld->num_attributes =0 ; + cld->regmap =devm_regmap_init_i2c (client, &cld_regmap_config); + cld->data = devm_kzalloc(cld->dev, sizeof(struct cld_data),
Quoted 7 lines
sizeof(*)drivers/misc/control-logic-device.c line 360
Quoted 3 lines
drivers/misc/control-logic-device.c new file +3
-0+ GFP_KERNEL); +if (!cld->data) { + ret = -ENOMEM ;return
We will revise this.
Quoted 16 lines
Quoted 16 lines
drivers/misc/control-logic-device.c new file +14
-0+ goto out; + } + +INIT_LIST_HEAD (&cld->data->list); + +sysfs_bin_attr_init (&cld->new_register_bin); + cld->new_register_bin.attr.name ="new_register" ; + cld->new_register_bin.attr.mode =0200 ; + cld->new_register_bin.write = cld_sysfs_new_register; + ret =sysfs_create_bin_file (&dev->kobj, &cld->new_register_bin); +if (ret) + goto out; + +sysfs_bin_attr_init (&cld->delet_register_bin);
Quoted 8 lines
drivers/misc/control-logic-device.c line 380
Quoted 6 lines
drivers/misc/control-logic-device.c new file +6
-0+ cld->delet_register_bin.attr.name ="delete_register" ; + cld->delet_register_bin.attr.mode =0200 ; + cld->delet_register_bin.write = cld_sysfs_delete_register; + ret =sysfs_create_bin_file (&dev->kobj, &cld->delet_register_bin); +if (ret) + goto out;return
We will revise this.
Quoted 7 lines
drivers/misc/control-logic-device.c line 384
Quoted 5 lines
drivers/misc/control-logic-device.c new file +4
-0+ + ops =of_device_get_match_data (cld->dev); +if (!ops) { + ret = -EINVAL ;return
We will revise this.
Quoted 11 lines
drivers/misc/control-logic-device.c line 391
Quoted 8 lines
drivers/misc/control-logic-device.c new file +7
-0+ goto out; + } + + ret = ops->load_registers (cld); + + cld->task =kthread_run (cld_monitor_thread, (void *)cld, +"register_monitor" );Why do you need the thread? What do you monitor? All this should be explained and documented.
The thread monitoring all the readable offsets and notify the userspace through kernfs_notify function if the offset value is changed. We will add the description in binding document.
Quoted 5 lines
drivers/misc/control-logic-device.c line 393
Quoted 3 lines
drivers/misc/control-logic-device.c new file +2
-0+if (IS_ERR (cld->task)) { + ret =PTR_ERR (cld->task);return
We will revise this.
Quoted 11 lines
drivers/misc/control-logic-device.c line 385
Quoted 2 lines
drivers/misc/control-logic-device.c new file +1
-0+ cld->task =NULL ;Drop
drivers/misc/control-logic-device.c line 398
Quoted 4 lines
drivers/misc/control-logic-device.c new file +4
-0+ goto out; + } + +dev_set_drvdata (dev, cld);This should happen before starting thread.
We will revise this.
Quoted 17 lines
Quoted 17 lines
drivers/misc/control-logic-device.c new file +16
-0+ +out: +return ret; +} + +static int cld_remove (struct i2c_client *client) { +struct device *dev = &client->dev; +struct cld_client *cld =dev_get_drvdata (dev); + +if (cld->task) { +kthread_stop (cld->task); + cld->task =NULL ; + } + +devm_kfree (dev, cld); +return 0 ;
Quoted 8 lines
drivers/misc/control-logic-device.c line 422
Quoted 6 lines
drivers/misc/control-logic-device.c new file +6
-0+} + +static const struct meta_cld_of_ops of_v1_ops = { + .load_registers = meta_cld_of_v1_load_registers, }; + +static const struct of_device_id cld_of_match[] = {This would warn now. Drop
of_match_ptr.
We will fix this.
Quoted 15 lines
drivers/misc/control-logic-device.c line 434
Quoted 13 lines
drivers/misc/control-logic-device.c new file +12
-0+ { + .compatible = "meta,control-logic-device-v1", + .data = &of_v1_ops, + }, + {} +}; + +MODULE_DEVICE_TABLE(of, cld_of_match) + +static struct i2c_driver cld = { + .driver = { .name ="cld-driver" , + .of_match_table =of_match_ptr (cld_of_match) },Blank line before }
We will fix this.
Quoted 13 lines
drivers/misc/control-logic-device.c line 443
Quoted 10 lines
drivers/misc/control-logic-device.c new file +9
-0+ .probe = cld_probe, + .remove = cld_remove, +}; + +module_i2c_driver (cld); + +MODULE_AUTHOR ("Ren Chen <[email protected]>" ); +MODULE_DESCRIPTION ("Meta control logic device driver" ); +MODULE_LICENSE ("GPL" );Best regards,
Krzysztof
Thanks,
Delphine
Re: [PATCH v1 3/3] misc: Add meta cld driver
Quoted 57 lines · Delphine_CC_Chiu/WYHQ/Wiwynn
Hi Krzysztof,
Thanks for your review comment.
Quoted 53 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Tuesday, January 17, 2023 6:55 PM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>; [email protected]; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>
Cc: [email protected]; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Stanislav Jakubek <[email protected]>; Linus Walleij <[email protected]>; Samuel Holland <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 3/3] misc: Add meta cld driverSecurity Reminder: Please be aware that this email is sent by an external
sender.Quoted 25 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>--- MAINTAINERS | 6 + drivers/misc/Kconfig | 9 + drivers/misc/Makefile | 1 + drivers/misc/control-logic-device.c | 443 ++++++++++++++++++++++++++++ 4 files changed, 459 insertions(+) create mode 100644 drivers/misc/control-logic-device.cMAINTAINERS index renamed from MAINTAINERS +0
-0
7483853880b6..46e250a2c334100644MAINTAINERS T: git git://linuxtv.org/media_tree.git · line 13395
Quoted 8 lines
MAINTAINERS +5
-0@@ -13388,6 +13388,12 @@ T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/amlogic,gx-vdec.yaml F: drivers/staging/media/meson/vdec/ +META CPLD DRIVER +M: Delphine CC Chiu <[email protected]> +L: [email protected] +S: Maintained +F:
Documentation/devicetree/bindings/misc/meta,control-logic-device.txt
Quoted 4 lines
Quoted 1 line
Missing entries for driver code.
We saw there are entries defined in
MAINTAINERSfile(M, R, L, S, W, Q, B, C, P, T, F, X, N, K). Could you guide us which entries are must to have?
The driver paths.
Quoted 8 lines
Quoted 6 lines
MAINTAINERS T: git git://linuxtv.org/media_tree.git · line 13399
Quoted 4 lines
MAINTAINERS +1
-0obj-$(CONFIG_OPEN_DICE) += open-dice.o obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o +obj-$(CONFIG_CONTROL_LOGIC_DEVICE) += control-logic-device.oDoes not look like ordered by name.
The file look like without ordered by name so we added the configuration in the tail.
Indeed, but don't add stuff to the end. Conflict-prone.
Best regards,
Krzysztof
Re: [PATCH v1 3/3] misc: Add meta cld driver
In reply to Delphine CC ChiuHi Delphine,
thanks for your patch!
Quoted 11 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>
Why should this driver be in drivers/misc and not drivers/mfd? MFS has support code for spawning child devices for the LED you are also creating for example, so please use that.
Quoted 1 line
+#include <
linux/sysfs.h>
(...)
Quoted 1 line
+#include <
linux/kthread.h>
(...)
Quoted 4 lines
drivers/misc/control-logic-device.c new file +4
-0+static ssize_t cld_register_read (struct file *flip,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t pos,size_t count) +{
(...)
Quoted 1 line
+
snprintf(buf, sizeof(value), "%d\n", value);
(...)
drivers/misc/control-logic-device.c line 84
Quoted 5 lines
drivers/misc/control-logic-device.c new file +5
-0+static ssize_t cld_register_write (struct file *flip,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t pos,size_t count) +{ + ret =kstrtoul (buf,0 , &val);
(...)
Writing and reading some random regmap registers is something that the regmap debugfs already can do.
drivers/misc/control-logic-device.c line 103
Quoted 3 lines
drivers/misc/control-logic-device.c new file +3
-0+static int cld_bin_register (struct cld_register_info info, +struct cld_client *cld) +{
And this is for reading and writing binary blobs.
It looks like something that should be using the firmware API.
If the purpose of the driver is to open a hole from userspace down to the hardware, as Greg says why not just use userspace I2C then?
It seems a bit dangerous to relay whatever the ASIC is doing to userspace though.
Are you sure you can't use any of the existing kernel functionality for doing what these userspace "hole" is doing?
There is drivers/power etc for power control and I bet it can be extended if need be.
Yours,
Linus Walleij
RE: [PATCH v1 3/3] misc: Add meta cld driver
Hi Linus Walleij,
Thanks for your review comment.
Quoted 30 lines
-----Original Message-----
From: Linus Walleij <[email protected]>
Sent: Tuesday, January 17, 2023 7:40 PM
To: Delphine_CC_Chiu/WYHQ/Wiwynn <[email protected]>
Cc: [email protected]; Derek Kiernan <[email protected]>; Dragan Cvetic <[email protected]>; Arnd Bergmann <[email protected]>; Greg Kroah-Hartman <[email protected]>; [email protected]; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Stanislav Jakubek <[email protected]>; Samuel Holland <[email protected]>; [email protected]; [email protected]; [email protected]; Lee Jones <[email protected]>; Sebastian Reichel <[email protected]>
Subject: Re: [PATCH v1 3/3] misc: Add meta cld driverSecurity Reminder: Please be aware that this email is sent by an external
sender.Hi Delphine,
thanks for your patch!
Quoted 5 lines · Delphine CC Chiu
Add support for meta control-logic-device driver. The CLD manages the server system power squence and other state such as host-power-state, uart-selection and presense-slots. The baseboard management controller (BMC) can access the CLD through I2C.
Quoted 8 lines
Quoted 6 lines
The version 1 of CLD driver is supported. The registers number, name and mode of CLD can be defined in dts file for version 1. The driver exports the filesystem following the dts setting.
Signed-off-by Delphine CC Chiu <[email protected]>Tested-by Bonnie Lo <[email protected]>Why should this driver be in
drivers/miscand notdrivers/mfd?
The cld device is not a physical ASIC. It's a controller based on FPGA device and the FPGA may be Altera or Lattice. So, we put the cld driver in misc folder. Is the cld driver suitable to put in mfd folder?
Quoted 2 lines
MFS has support code for spawning child devices for the LED you are also creating for example, so please use that.
Could you please guide us which device driver we can refer?
Quoted 32 lines
Quoted 2 lines
+#include <
linux/sysfs.h>(...)
Quoted 1 line
+#include <
linux/kthread.h>(...)
Quoted 3 lines
drivers/misc/control-logic-device.c new file +3
-0+static ssize_t cld_register_read (struct file *flip,struct kobject *kobj, +struct bin_attribute *attr,char *buf, +loff_t pos,size_t count) {(...)
Quoted 1 line
+
snprintf(buf, sizeof(value), "%d\n", value);(...)
Review
Quoted 2 lines
(quoted diff) +2
-0+static ssize_t cld_register_write(struct file *flip, struct kobject *kobj, + struct bin_attribute *attr, char*buf,
Review
Quoted 2 lines
(quoted diff) +2
-0+ loff_t pos, size_t count) { + ret = kstrtoul(buf, 0, &val);(...)
Writing and reading some random regmap registers is something that the regmap debugfs already can do.
Review
Quoted 2 lines
(quoted diff) +2
-0+static int cld_bin_register(struct cld_register_info info, + struct cld_client *cld) {And this is for reading and writing binary blobs.
It looks like something that should be using the firmware API.
If the purpose of the driver is to open a hole from userspace down to the hardware, as Greg says why not just use userspace I2C then?
Quoted 8 lines
It seems a bit dangerous to relay whatever the ASIC is doing to userspace though.
Are you sure you can't use any of the existing kernel functionality for doing what these userspace "hole" is doing?
There is
drivers/poweretc for power control and I bet it can be extended if need be.
We will discuss with our customer.
Quoted 3 lines
Yours,
Linus Walleij
Thanks,
Delphine
Re: [PATCH v1 3/3] misc: Add meta cld driver
Quoted 6 lines · Delphine_CC_Chiu/WYHQ/Wiwynn
Quoted 4 lines
On Tue, Jan 17, 2023 at 10:46 AM Delphine CC Chiu
<[email protected]> wrote:Why should this driver be in
drivers/miscand notdrivers/mfd?The cld device is not a physical ASIC.
Nobody cares about the difference, that is only a convention. It has a stable hardware/software API that is all that matters.
Quoted 2 lines
It's a controller based on FPGA device and the FPGA may be Altera or Lattice. So, we put the cld driver in misc folder. Is the cld driver suitable to put in mfd folder?
Yes.
Quoted 4 lines
Quoted 2 lines
MFS has support code for spawning child devices for the LED you are also creating for example, so please use that.
Could you please guide us which device driver we can refer?
For example drivers/mfd/stmfx.c another firmware-driven FPGA thing.
Yours,
Linus Walleij