[PATCH v2] base: soc: Handle custom soc information sysfs entries

2019-10-07 Thread Murali Nalajala
Soc framework exposed sysfs entries are not sufficient for some
of the h/w platforms. Currently there is no interface where soc
drivers can expose further information about their SoCs via soc
framework. This change address this limitation where clients can
pass their custom entries as attribute group and soc framework
would expose them as sysfs properties.

Signed-off-by: Murali Nalajala 
---
Changes in v2:
- Address comments from Stephen Boyd about "soc_dev" clean up in error paths.

Changes in v1:
- Remove NULL initialization of "soc_attr_groups"
- Taken care of freeing "soc_attr_groups" in soc_release()
- Addressed Stephen Boyd comments on usage of "kalloc"

 drivers/base/soc.c  | 30 +-
 include/linux/sys_soc.h |  1 +
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 7c0c5ca..4af11a4 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -104,15 +104,12 @@ static ssize_t soc_info_get(struct device *dev,
.is_visible = soc_attribute_mode,
 };
 
-static const struct attribute_group *soc_attr_groups[] = {
-   _attr_group,
-   NULL,
-};
-
 static void soc_release(struct device *dev)
 {
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
 
+   ida_simple_remove(_ida, soc_dev->soc_dev_num);
+   kfree(soc_dev->dev.groups);
kfree(soc_dev);
 }
 
@@ -121,6 +118,7 @@ static void soc_release(struct device *dev)
 struct soc_device *soc_device_register(struct soc_device_attribute 
*soc_dev_attr)
 {
struct soc_device *soc_dev;
+   const struct attribute_group **soc_attr_groups;
int ret;
 
if (!soc_bus_type.p) {
@@ -136,10 +134,18 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
goto out1;
}
 
+   soc_attr_groups = kcalloc(3, sizeof(*soc_attr_groups), GFP_KERNEL);
+   if (!soc_attr_groups) {
+   ret = -ENOMEM;
+   goto out2;
+   }
+   soc_attr_groups[0] = _attr_group;
+   soc_attr_groups[1] = soc_dev_attr->custom_attr_group;
+
/* Fetch a unique (reclaimable) SOC ID. */
ret = ida_simple_get(_ida, 0, 0, GFP_KERNEL);
if (ret < 0)
-   goto out2;
+   goto out3;
soc_dev->soc_dev_num = ret;
 
soc_dev->attr = soc_dev_attr;
@@ -150,15 +156,15 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
dev_set_name(_dev->dev, "soc%d", soc_dev->soc_dev_num);
 
ret = device_register(_dev->dev);
-   if (ret)
-   goto out3;
+   if (ret) {
+   put_device(_dev->dev);
+   return ERR_PTR(ret);
+   }
 
return soc_dev;
 
 out3:
-   ida_simple_remove(_ida, soc_dev->soc_dev_num);
-   put_device(_dev->dev);
-   soc_dev = NULL;
+   kfree(soc_attr_groups);
 out2:
kfree(soc_dev);
 out1:
@@ -169,8 +175,6 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 /* Ensure soc_dev->attr is freed prior to calling soc_device_unregister. */
 void soc_device_unregister(struct soc_device *soc_dev)
 {
-   ida_simple_remove(_ida, soc_dev->soc_dev_num);
-
device_unregister(_dev->dev);
early_soc_dev_attr = NULL;
 }
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index 48ceea8..d9b3cf0 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -15,6 +15,7 @@ struct soc_device_attribute {
const char *serial_number;
const char *soc_id;
const void *data;
+   const struct attribute_group *custom_attr_group;
 };
 
 /**
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH v1] base: soc: Handle custom soc information sysfs entries

2019-10-03 Thread Murali Nalajala
Soc framework exposed sysfs entries are not sufficient for some
of the h/w platforms. Currently there is no interface where soc
drivers can expose further information about their SoCs via soc
framework. This change address this limitation where clients can
pass their custom entries as attribute group and soc framework
would expose them as sysfs properties.

Signed-off-by: Murali Nalajala 
---
Changes in v1:
- Remove NULL initialization of "soc_attr_groups"
- Taken care of freeing "soc_attr_groups" in soc_release()
- Addressed Stephen Boyd comments on usage of "kalloc"

 drivers/base/soc.c  | 23 +++
 include/linux/sys_soc.h |  1 +
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 7c0c5ca..ad30d58 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -104,15 +104,11 @@ static ssize_t soc_info_get(struct device *dev,
.is_visible = soc_attribute_mode,
 };
 
-static const struct attribute_group *soc_attr_groups[] = {
-   _attr_group,
-   NULL,
-};
-
 static void soc_release(struct device *dev)
 {
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
 
+   kfree(soc_dev->dev.groups);
kfree(soc_dev);
 }
 
@@ -121,6 +117,7 @@ static void soc_release(struct device *dev)
 struct soc_device *soc_device_register(struct soc_device_attribute 
*soc_dev_attr)
 {
struct soc_device *soc_dev;
+   const struct attribute_group **soc_attr_groups;
int ret;
 
if (!soc_bus_type.p) {
@@ -136,10 +133,18 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
goto out1;
}
 
+   soc_attr_groups = kcalloc(3, sizeof(*soc_attr_groups), GFP_KERNEL);
+   if (!soc_attr_groups) {
+   ret = -ENOMEM;
+   goto out2;
+   }
+   soc_attr_groups[0] = _attr_group;
+   soc_attr_groups[1] = soc_dev_attr->custom_attr_group;
+
/* Fetch a unique (reclaimable) SOC ID. */
ret = ida_simple_get(_ida, 0, 0, GFP_KERNEL);
if (ret < 0)
-   goto out2;
+   goto out3;
soc_dev->soc_dev_num = ret;
 
soc_dev->attr = soc_dev_attr;
@@ -151,14 +156,16 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 
ret = device_register(_dev->dev);
if (ret)
-   goto out3;
+   goto out4;
 
return soc_dev;
 
-out3:
+out4:
ida_simple_remove(_ida, soc_dev->soc_dev_num);
put_device(_dev->dev);
soc_dev = NULL;
+out3:
+   kfree(soc_attr_groups);
 out2:
kfree(soc_dev);
 out1:
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index 48ceea8..d9b3cf0 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -15,6 +15,7 @@ struct soc_device_attribute {
const char *serial_number;
const char *soc_id;
const void *data;
+   const struct attribute_group *custom_attr_group;
 };
 
 /**
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH] base: soc: Handle custom soc information sysfs entries

2019-10-02 Thread Murali Nalajala
Soc framework exposed sysfs entries are not sufficient for some
of the h/w platforms. Currently there is no interface where soc
drivers can expose further information about their SoCs via soc
framework. This change address this limitation where clients can
pass their custom entries as attribute group and soc framework
would expose them as sysfs properties.

Signed-off-by: Murali Nalajala 
---
 drivers/base/soc.c  | 26 ++
 include/linux/sys_soc.h |  1 +
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 7c0c5ca..ec70a58 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -15,6 +15,8 @@
 #include 
 #include 
 
+#define NUM_ATTR_GROUPS 3
+
 static DEFINE_IDA(soc_ida);
 
 static ssize_t soc_info_get(struct device *dev,
@@ -104,11 +106,6 @@ static ssize_t soc_info_get(struct device *dev,
.is_visible = soc_attribute_mode,
 };
 
-static const struct attribute_group *soc_attr_groups[] = {
-   _attr_group,
-   NULL,
-};
-
 static void soc_release(struct device *dev)
 {
struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
@@ -121,6 +118,7 @@ static void soc_release(struct device *dev)
 struct soc_device *soc_device_register(struct soc_device_attribute 
*soc_dev_attr)
 {
struct soc_device *soc_dev;
+   const struct attribute_group **soc_attr_groups = NULL;
int ret;
 
if (!soc_bus_type.p) {
@@ -136,10 +134,20 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
goto out1;
}
 
+   soc_attr_groups = kzalloc(sizeof(*soc_attr_groups) *
+   NUM_ATTR_GROUPS, GFP_KERNEL);
+   if (!soc_attr_groups) {
+   ret = -ENOMEM;
+   goto out2;
+   }
+   soc_attr_groups[0] = _attr_group;
+   soc_attr_groups[1] = soc_dev_attr->custom_attr_group;
+   soc_attr_groups[2] = NULL;
+
/* Fetch a unique (reclaimable) SOC ID. */
ret = ida_simple_get(_ida, 0, 0, GFP_KERNEL);
if (ret < 0)
-   goto out2;
+   goto out3;
soc_dev->soc_dev_num = ret;
 
soc_dev->attr = soc_dev_attr;
@@ -151,14 +159,16 @@ struct soc_device *soc_device_register(struct 
soc_device_attribute *soc_dev_attr
 
ret = device_register(_dev->dev);
if (ret)
-   goto out3;
+   goto out4;
 
return soc_dev;
 
-out3:
+out4:
ida_simple_remove(_ida, soc_dev->soc_dev_num);
put_device(_dev->dev);
soc_dev = NULL;
+out3:
+   kfree(soc_attr_groups);
 out2:
kfree(soc_dev);
 out1:
diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h
index 48ceea8..d9b3cf0 100644
--- a/include/linux/sys_soc.h
+++ b/include/linux/sys_soc.h
@@ -15,6 +15,7 @@ struct soc_device_attribute {
const char *serial_number;
const char *soc_id;
const void *data;
+   const struct attribute_group *custom_attr_group;
 };
 
 /**
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



[PATCH] base: soc: Export soc_device_to_device API

2019-09-19 Thread Murali Nalajala
If the soc drivers want to add custom sysfs entries it needs to
access "dev" field in "struct soc_device". This can be achieved
by "soc_device_to_device" API. Soc drivers which are built as a
module they need above API to be exported. Otherwise one can
observe compilation issues.

Signed-off-by: Murali Nalajala 
---
 drivers/base/soc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/soc.c b/drivers/base/soc.c
index 7c0c5ca..4ad52f6 100644
--- a/drivers/base/soc.c
+++ b/drivers/base/soc.c
@@ -41,6 +41,7 @@ struct device *soc_device_to_device(struct soc_device 
*soc_dev)
 {
return _dev->dev;
 }
+EXPORT_SYMBOL_GPL(soc_device_to_device);
 
 static umode_t soc_attribute_mode(struct kobject *kobj,
struct attribute *attr,
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project