Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Aug 2019 08:08:56 +0000 (UTC)
From:      Michal Meloun <mmel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r351184 - in head/sys/dev: extres/syscon fdt
Message-ID:  <201908180808.x7I88uwS080448@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mmel
Date: Sun Aug 18 08:08:56 2019
New Revision: 351184
URL: https://svnweb.freebsd.org/changeset/base/351184

Log:
  Add method for getting of syscon handle from parent device.
  
  If simple multifuction device also provides syscon interface, its
  childern should be able to consume it. Due to this:
  - declare coresponding method in syscon interface
  - implement it in simple multifunction device driver
  
  MFC after:	1 week

Modified:
  head/sys/dev/extres/syscon/syscon.c
  head/sys/dev/extres/syscon/syscon_if.m
  head/sys/dev/fdt/simple_mfd.c

Modified: head/sys/dev/extres/syscon/syscon.c
==============================================================================
--- head/sys/dev/extres/syscon/syscon.c	Sun Aug 18 08:07:31 2019	(r351183)
+++ head/sys/dev/extres/syscon/syscon.c	Sun Aug 18 08:08:56 2019	(r351184)
@@ -254,3 +254,14 @@ syscon_get_by_ofw_property(device_t cdev, phandle_t cn
 	return (0);
 }
 #endif
+
+int
+syscon_get_handle_default(device_t dev, struct syscon **syscon)
+{
+	device_t parent;
+
+	parent = device_get_parent(dev);
+	if (parent == NULL)
+		return (ENODEV);
+	return (SYSCON_GET_HANDLE(parent, syscon));
+}

Modified: head/sys/dev/extres/syscon/syscon_if.m
==============================================================================
--- head/sys/dev/extres/syscon/syscon_if.m	Sun Aug 18 08:07:31 2019	(r351183)
+++ head/sys/dev/extres/syscon/syscon_if.m	Sun Aug 18 08:08:56 2019	(r351184)
@@ -32,6 +32,7 @@ INTERFACE syscon;
 
 HEADER {
 	struct syscon;
+	int syscon_get_handle_default(device_t dev, struct syscon **syscon);
 }
 
 METHOD int init {
@@ -62,3 +63,11 @@ METHOD int modify_4 {
 	uint32_t	clear_bits;
 	uint32_t	set_bits;
 };
+
+/**
+ * Get syscon handle from parent driver
+ */
+METHOD int get_handle {
+	device_t	dev;
+	struct syscon	**syscon;
+} DEFAULT syscon_get_handle_default;

Modified: head/sys/dev/fdt/simple_mfd.c
==============================================================================
--- head/sys/dev/fdt/simple_mfd.c	Sun Aug 18 08:07:31 2019	(r351183)
+++ head/sys/dev/fdt/simple_mfd.c	Sun Aug 18 08:08:56 2019	(r351184)
@@ -49,14 +49,16 @@ __FBSDID("$FreeBSD$");
 
 device_t simple_mfd_add_device(device_t dev, phandle_t node, u_int order,
     const char *name, int unit, struct simplebus_devinfo *di);
-struct simplebus_devinfo *simple_mfd_setup_dinfo(device_t dev, phandle_t node, struct simplebus_devinfo *di);
+struct simplebus_devinfo *simple_mfd_setup_dinfo(device_t dev, phandle_t node,
+    struct simplebus_devinfo *di);
 
 #include "syscon_if.h"
 #include <dev/extres/syscon/syscon.h>
 
 MALLOC_DECLARE(M_SYSCON);
 
-static uint32_t simple_mfd_syscon_read_4(struct syscon *syscon, bus_size_t offset);
+static uint32_t simple_mfd_syscon_read_4(struct syscon *syscon,
+    bus_size_t offset);
 static int simple_mfd_syscon_write_4(struct syscon *syscon, bus_size_t offset,
     uint32_t val);
 static int simple_mfd_syscon_modify_4(struct syscon *syscon, bus_size_t offset,
@@ -125,7 +127,18 @@ simple_mfd_syscon_modify_4(struct syscon *syscon, bus_
 	SYSCON_UNLOCK(sc);
 	return (0);
 }
+static int
+simple_mfd_syscon_get_handle(device_t dev, struct syscon **syscon)
+{
+	struct simple_mfd_softc *sc;
 
+	sc = device_get_softc(dev);
+	*syscon = sc->syscon;
+	if (syscon == NULL)
+		return (ENODEV);
+	return (0);
+}
+
 static int
 simple_mfd_probe(device_t dev)
 {
@@ -278,6 +291,8 @@ simple_mfd_add_device(device_t dev, phandle_t node, u_
 }
 
 static device_method_t simple_mfd_methods[] = {
+	/* syscon interface */
+	DEVMETHOD(syscon_get_handle,	simple_mfd_syscon_get_handle),
 	/* Device interface */
 	DEVMETHOD(device_probe,		simple_mfd_probe),
 	DEVMETHOD(device_attach,	simple_mfd_attach),



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201908180808.x7I88uwS080448>