slimbus: Support ability to specify maximum and minimum clock gears

Slimbus can run in clock gears 1 through 10 per spec. Scheduling
algorithm tries to find the optimum clock gear depending on bandwidth
usage for messaging and active data channels.
However, not all controllers may have the ability to support all the
10 clock gears. This patch provides ability so that scheduling
algorithm will only run the bus in supported slimbus clock gear.
Controllers can specify supported minimum and maximum clock gear
during registration with the framework.

Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
diff --git a/drivers/slimbus/slimbus.c b/drivers/slimbus/slimbus.c
index 59bb008..313837a 100644
--- a/drivers/slimbus/slimbus.c
+++ b/drivers/slimbus/slimbus.c
@@ -379,6 +379,10 @@
 	ctrl->dev.type = &slim_ctrl_type;
 	ctrl->dev.parent = &slimbus_dev;
 	ctrl->num_dev = 0;
+	if (!ctrl->min_cg)
+		ctrl->min_cg = SLIM_MIN_CLK_GEAR;
+	if (!ctrl->max_cg)
+		ctrl->max_cg = SLIM_MAX_CLK_GEAR;
 	mutex_init(&ctrl->m_ctrl);
 	mutex_init(&ctrl->sched.m_reconf);
 	ret = device_register(&ctrl->dev);
@@ -2200,7 +2204,7 @@
 	dev_dbg(&ctrl->dev, "pending:chan sl:%u, :msg sl:%u, clkgear:%u\n",
 				ctrl->sched.usedslots,
 				ctrl->sched.pending_msgsl, *clkgear);
-	while ((usedsl * 2 <= availsl) && (*clkgear > 1)) {
+	while ((usedsl * 2 <= availsl) && (*clkgear > ctrl->min_cg)) {
 		*clkgear -= 1;
 		usedsl *= 2;
 	}
@@ -2210,14 +2214,14 @@
 	 * can be scheduled, or reserved BW can't be satisfied, increase clock
 	 * gear and try again
 	 */
-	for (; *clkgear <= SLIM_MAX_CLK_GEAR; (*clkgear)++) {
+	for (; *clkgear <= ctrl->max_cg; (*clkgear)++) {
 		ret = slim_sched_chans(sb, *clkgear, &ctrlw, &subfrml);
 
 		if (ret == 0) {
 			*subfrmc = getsubfrmcoding(&ctrlw, &subfrml, &msgsl);
-			if ((msgsl >> (SLIM_MAX_CLK_GEAR - *clkgear) <
+			if ((msgsl >> (ctrl->max_cg - *clkgear) <
 				ctrl->sched.pending_msgsl) &&
-				(*clkgear < SLIM_MAX_CLK_GEAR))
+				(*clkgear < ctrl->max_cg))
 				continue;
 			else
 				break;
diff --git a/include/linux/slimbus/slimbus.h b/include/linux/slimbus/slimbus.h
index fc76b77..79dabce5 100644
--- a/include/linux/slimbus/slimbus.h
+++ b/include/linux/slimbus/slimbus.h
@@ -25,6 +25,7 @@
 #define SLIM_CL_PER_SUPERFRAME		6144
 #define SLIM_CL_PER_SUPERFRAME_DIV8	(SLIM_CL_PER_SUPERFRAME >> 3)
 #define SLIM_MAX_CLK_GEAR		10
+#define SLIM_MIN_CLK_GEAR		1
 #define SLIM_CL_PER_SL			4
 #define SLIM_SL_PER_SUPERFRAME		(SLIM_CL_PER_SUPERFRAME >> 2)
 #define SLIM_FRM_SLOTS_PER_SUPERFRAME	16
@@ -424,6 +425,8 @@
  * @list: Link with other slimbus controllers
  * @name: Name for this controller
  * @clkgear: Current clock gear in which this bus is running
+ * @min_cg: Minimum clock gear supported by this controller (default value: 1)
+ * @max_cg: Maximum clock gear supported by this controller (default value: 10)
  * @a_framer: Active framer which is clocking the bus managed by this controller
  * @m_ctrl: Mutex protecting controller data structures (ports, channels etc)
  * @addrt: Logical address table
@@ -461,6 +464,8 @@
 	struct list_head	list;
 	char			name[SLIMBUS_NAME_SIZE];
 	int			clkgear;
+	int			min_cg;
+	int			max_cg;
 	struct slim_framer	*a_framer;
 	struct mutex		m_ctrl;
 	struct slim_addrt	*addrt;