All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] export applesmc_{read,write,has}_key functions
@ 2017-06-16  9:02 Florian Echtler
  2017-06-16 16:41 ` Guenter Roeck
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Echtler @ 2017-06-16  9:02 UTC (permalink / raw)
  To: linux-hwmon; +Cc: linux, rydberg, rydberg, Florian Echtler

This patch exports the SMC key access functions from applesmc.c to allow
access from other drivers, in particular, the yet-to-be-written ACPI 
driver for Target Display Mode (TDM).

Signed-off-by: Florian Echtler <floe@butterbrot.org>
---
 drivers/hwmon/applesmc.c | 10 +++++++---
 include/linux/applesmc.h | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 3 deletions(-)
 create mode 100644 include/linux/applesmc.h

diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 0af7fd3..ec637c1 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -44,6 +44,7 @@
 #include <linux/hwmon.h>
 #include <linux/workqueue.h>
 #include <linux/err.h>
+#include <linux/applesmc.h>
 
 /* data port used by Apple SMC */
 #define APPLESMC_DATA_PORT	0x300
@@ -433,7 +434,7 @@ static const struct applesmc_entry *applesmc_get_entry_by_key(const char *key)
 	return applesmc_get_entry_by_index(begin);
 }
 
-static int applesmc_read_key(const char *key, u8 *buffer, u8 len)
+int applesmc_read_key(const char *key, u8 *buffer, u8 len)
 {
 	const struct applesmc_entry *entry;
 
@@ -443,8 +444,9 @@ static int applesmc_read_key(const char *key, u8 *buffer, u8 len)
 
 	return applesmc_read_entry(entry, buffer, len);
 }
+EXPORT_SYMBOL(applesmc_read_key);
 
-static int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
+int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
 {
 	const struct applesmc_entry *entry;
 
@@ -454,8 +456,9 @@ static int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
 
 	return applesmc_write_entry(entry, buffer, len);
 }
+EXPORT_SYMBOL(applesmc_write_key);
 
-static int applesmc_has_key(const char *key, bool *value)
+int applesmc_has_key(const char *key, bool *value)
 {
 	const struct applesmc_entry *entry;
 
@@ -466,6 +469,7 @@ static int applesmc_has_key(const char *key, bool *value)
 	*value = !IS_ERR(entry);
 	return 0;
 }
+EXPORT_SYMBOL(applesmc_has_key);
 
 /*
  * applesmc_read_s16 - Read 16-bit signed big endian register
diff --git a/include/linux/applesmc.h b/include/linux/applesmc.h
new file mode 100644
index 0000000..932d352
--- /dev/null
+++ b/include/linux/applesmc.h
@@ -0,0 +1,39 @@
+/*
+ * applesmc.h - functions to read/write keys in the Apple SMC
+ *
+ * Copyright (c) 2017 Florian 'floe' Echtler <floe@butterbrot.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _LINUX_APPLESMC_H_
+#define _LINUX_APPLESMC_H_
+
+#if defined(CONFIG_SENSORS_APPLESMC)
+
+int applesmc_has_key(const char *key, bool *value);
+int applesmc_read_key(const char *key, u8 *buffer, u8 len);
+int applesmc_write_key(const char *key, const u8 *buffer, u8 len);
+
+#endif
+#endif /* _LINUX_APPLESMC_H_ */
+
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] export applesmc_{read,write,has}_key functions
  2017-06-16  9:02 [PATCH] export applesmc_{read,write,has}_key functions Florian Echtler
@ 2017-06-16 16:41 ` Guenter Roeck
  2017-06-21  9:15   ` Florian Echtler
  0 siblings, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2017-06-16 16:41 UTC (permalink / raw)
  To: Florian Echtler; +Cc: linux-hwmon, rydberg, rydberg

On Fri, Jun 16, 2017 at 11:02:31AM +0200, Florian Echtler wrote:
> This patch exports the SMC key access functions from applesmc.c to allow
> access from other drivers, in particular, the yet-to-be-written ACPI 
> driver for Target Display Mode (TDM).
> 

It is structurally deficient to have the hwmon driver export those functions.
If used by another driver, the functions should be moved to a common
driver, possibly in mfd. This driver would then also be responsible to
instantiate its child drivers.

FWIW, the applesmc hwmon driver should be split into separate drivers,
but that is a different issue.

Guenter

> Signed-off-by: Florian Echtler <floe@butterbrot.org>
> ---
>  drivers/hwmon/applesmc.c | 10 +++++++---
>  include/linux/applesmc.h | 39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 46 insertions(+), 3 deletions(-)
>  create mode 100644 include/linux/applesmc.h
> 
> diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
> index 0af7fd3..ec637c1 100644
> --- a/drivers/hwmon/applesmc.c
> +++ b/drivers/hwmon/applesmc.c
> @@ -44,6 +44,7 @@
>  #include <linux/hwmon.h>
>  #include <linux/workqueue.h>
>  #include <linux/err.h>
> +#include <linux/applesmc.h>
>  
>  /* data port used by Apple SMC */
>  #define APPLESMC_DATA_PORT	0x300
> @@ -433,7 +434,7 @@ static const struct applesmc_entry *applesmc_get_entry_by_key(const char *key)
>  	return applesmc_get_entry_by_index(begin);
>  }
>  
> -static int applesmc_read_key(const char *key, u8 *buffer, u8 len)
> +int applesmc_read_key(const char *key, u8 *buffer, u8 len)
>  {
>  	const struct applesmc_entry *entry;
>  
> @@ -443,8 +444,9 @@ static int applesmc_read_key(const char *key, u8 *buffer, u8 len)
>  
>  	return applesmc_read_entry(entry, buffer, len);
>  }
> +EXPORT_SYMBOL(applesmc_read_key);
>  
> -static int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
> +int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
>  {
>  	const struct applesmc_entry *entry;
>  
> @@ -454,8 +456,9 @@ static int applesmc_write_key(const char *key, const u8 *buffer, u8 len)
>  
>  	return applesmc_write_entry(entry, buffer, len);
>  }
> +EXPORT_SYMBOL(applesmc_write_key);
>  
> -static int applesmc_has_key(const char *key, bool *value)
> +int applesmc_has_key(const char *key, bool *value)
>  {
>  	const struct applesmc_entry *entry;
>  
> @@ -466,6 +469,7 @@ static int applesmc_has_key(const char *key, bool *value)
>  	*value = !IS_ERR(entry);
>  	return 0;
>  }
> +EXPORT_SYMBOL(applesmc_has_key);
>  
>  /*
>   * applesmc_read_s16 - Read 16-bit signed big endian register
> diff --git a/include/linux/applesmc.h b/include/linux/applesmc.h
> new file mode 100644
> index 0000000..932d352
> --- /dev/null
> +++ b/include/linux/applesmc.h
> @@ -0,0 +1,39 @@
> +/*
> + * applesmc.h - functions to read/write keys in the Apple SMC
> + *
> + * Copyright (c) 2017 Florian 'floe' Echtler <floe@butterbrot.org>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS
> + * IN THE SOFTWARE.
> + *
> + */
> +
> +#ifndef _LINUX_APPLESMC_H_
> +#define _LINUX_APPLESMC_H_
> +
> +#if defined(CONFIG_SENSORS_APPLESMC)
> +
> +int applesmc_has_key(const char *key, bool *value);
> +int applesmc_read_key(const char *key, u8 *buffer, u8 len);
> +int applesmc_write_key(const char *key, const u8 *buffer, u8 len);
> +
> +#endif
> +#endif /* _LINUX_APPLESMC_H_ */
> +
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] export applesmc_{read,write,has}_key functions
  2017-06-16 16:41 ` Guenter Roeck
@ 2017-06-21  9:15   ` Florian Echtler
  2017-07-07 18:24     ` Guenter Roeck
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Echtler @ 2017-06-21  9:15 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-hwmon, rydberg, rydberg


[-- Attachment #1.1: Type: text/plain, Size: 857 bytes --]

On 16.06.2017 18:41, Guenter Roeck wrote:
> On Fri, Jun 16, 2017 at 11:02:31AM +0200, Florian Echtler wrote:
>> This patch exports the SMC key access functions from applesmc.c to allow
>> access from other drivers, in particular, the yet-to-be-written ACPI 
>> driver for Target Display Mode (TDM).
> 
> It is structurally deficient to have the hwmon driver export those functions.
> If used by another driver, the functions should be moved to a common
> driver, possibly in mfd. This driver would then also be responsible to
> instantiate its child drivers.

Hm, this sounds like a major rework? AFAICT, that would roughly mean to move all
code up to, but not including, applesmc_calibrate to mfd and leave the rest in
hwmon?

What's the mechanism to auto-load another kernel module?

Best, Florian
-- 
SENT FROM MY DEC VT50 TERMINAL


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] export applesmc_{read,write,has}_key functions
  2017-06-21  9:15   ` Florian Echtler
@ 2017-07-07 18:24     ` Guenter Roeck
  0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2017-07-07 18:24 UTC (permalink / raw)
  To: Florian Echtler; +Cc: linux-hwmon, rydberg, rydberg

On Wed, Jun 21, 2017 at 11:15:11AM +0200, Florian Echtler wrote:
> On 16.06.2017 18:41, Guenter Roeck wrote:
> > On Fri, Jun 16, 2017 at 11:02:31AM +0200, Florian Echtler wrote:
> >> This patch exports the SMC key access functions from applesmc.c to allow
> >> access from other drivers, in particular, the yet-to-be-written ACPI 
> >> driver for Target Display Mode (TDM).
> > 
> > It is structurally deficient to have the hwmon driver export those functions.
> > If used by another driver, the functions should be moved to a common
> > driver, possibly in mfd. This driver would then also be responsible to
> > instantiate its child drivers.
> 
> Hm, this sounds like a major rework? AFAICT, that would roughly mean to move all
> code up to, but not including, applesmc_calibrate to mfd and leave the rest in
> hwmon?
> 
Sorry for the late reply.

Yes, this is asking for a major rework. At some point we just have to stop
adding more and more functionality to a single driver.

> What's the mechanism to auto-load another kernel module?
> 
Primarily MODULE_ALIAS and MODULE_DEVICE_TABLE. mfd drivers often use
platform_device_add() to create child devices, or mfd_add_devices().

Guenter

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-07 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-16  9:02 [PATCH] export applesmc_{read,write,has}_key functions Florian Echtler
2017-06-16 16:41 ` Guenter Roeck
2017-06-21  9:15   ` Florian Echtler
2017-07-07 18:24     ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.