OSDN Git Service

Enable .panel and .rotation specifiers in property files
authorPatrick Porlan <patrick.porlan@intel.com>
Tue, 19 Aug 2014 09:54:44 +0000 (11:54 +0200)
committerAdriana Reus <adriana.reus@intel.com>
Wed, 3 Sep 2014 07:53:38 +0000 (10:53 +0300)
This is a convenient way to check or override PLD settings
during development. These are of course optional, per sensor,
and if found the BIOS values are ignored.

Change-Id: I03fadb70245476d49df5bd9167980e9fad9a662d
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
description.c
description.h
enumeration.c

index 7334d5f..2c6fec0 100644 (file)
@@ -51,7 +51,7 @@
  * ro.iio.illuminance.power = .001
  * ro.iio.illuminance.illumincalib = 7400
  *
- * Finally there's a 'opt_scale' specifier, documented as follows:
+ * There's a 'opt_scale' specifier, documented as follows:
  *
  *  This adds support for a scaling factor that can be expressed
  *  using properties, for all sensors, on a channel basis. That
  *  For sensors using a single channel - and only those - the channel
  *  name is implicitly void and a syntax such as ro.iio.illuminance.
  *  opt_scale = 3 has to be used.
+ *
+ * 'panel' and 'rotation' specifiers can be used to express ACPI PLD placement
+ * information ; if found they will be used in priority over the actual ACPI
+ * data. That is intended as a way to verify values during development.
  */
 
 static int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE])
@@ -87,6 +91,18 @@ static int sensor_get_st_prop (int s, const char* sel, char val[MAX_NAME_SIZE])
 }
 
 
+int sensor_get_prop (int s, const char* sel, int* val)
+{
+       char buf[MAX_NAME_SIZE];
+
+       if (sensor_get_st_prop(s, sel, buf))
+               return -1;
+
+       *val = atoi(buf);
+       return 0;
+}
+
+
 int sensor_get_fl_prop (int s, const char* sel, float* val)
 {
        char buf[MAX_NAME_SIZE];
index 8807122..abeb6ee 100644 (file)
@@ -21,7 +21,8 @@ float sensor_get_resolution   (int handle);
 float  sensor_get_power        (int handle);
 float  sensor_get_illumincalib (int handle);
 
-int            sensor_get_fl_prop (int s, const char* sel, float* val);
+int            sensor_get_prop         (int s, const char* sel, int* val);
+int            sensor_get_fl_prop      (int s, const char* sel, float* val);
 
 int            sensor_get_order        (int s, unsigned char map[MAX_CHANNELS]);
 
index 43aef75..236e74d 100644 (file)
@@ -107,39 +107,88 @@ static void setup_properties_from_pld(int s, int panel, int rotation,
        sensor_info[s].channel[2].opt_scale = z;
 }
 
-static void decode_placement_information (int dev_num, int num_channels, int s)
+
+static int is_valid_pld (int panel, int rotation)
 {
-       /*
-        * See if we have optional "physical location of device" ACPI tags.
-        * We're only interested in panel and rotation specifiers.
-        */
+       if (panel != 4 && panel != 5) { /* 4 = front ; 5 = back */
+               ALOGW("Unhandled PLD panel spec: %d\n", panel);
+               return 0;
+       }
+
+       /* Only deal with 90° rotations for now */
+       if (rotation < 0 || rotation > 7 || (rotation & 1)) {
+               ALOGW("Unhandled PLD rotation spec: %d\n", rotation);
+               return 0;
+       }
+
+       return 1;
+}
+
+
+static int read_pld_from_properties (int s, int* panel, int* rotation)
+{
+       int p, r;
+
+       if (sensor_get_prop(s, "panel", &p))
+               return -1;
+
+       if (sensor_get_prop(s, "rotation", &r))
+               return -1;
+
+       if (!is_valid_pld(p, r))
+               return -1;
+
+       *panel = p;
+       *rotation = r;
+
+       ALOGI("S%d PLD from properties: panel=%d, rotation=%d\n", s, p, r);
+
+       return 0;
+}
+
 
+static int read_pld_from_sysfs (int s, int dev_num, int* panel, int* rotation)
+{
        char sysfs_path[PATH_MAX];
-       int panel;
-       int rotation;
+       int p,r;
 
        sprintf(sysfs_path, BASE_PATH "../firmware_node/pld/panel", dev_num);
 
-       if (sysfs_read_int(sysfs_path, &panel))
-               return; /* Attribute not found */
+       if (sysfs_read_int(sysfs_path, &p))
+               return -1;
 
        sprintf(sysfs_path, BASE_PATH "../firmware_node/pld/rotation", dev_num);
 
-       if (sysfs_read_int(sysfs_path, &rotation))
-               return; /* Attribute not found */
+       if (sysfs_read_int(sysfs_path, &r))
+               return -1;
 
-       ALOGI("Found PLD for S%d: panel=%d, rotation=%d\n", s, panel, rotation);
+       if (!is_valid_pld(p, r))
+               return -1;
 
-       if (panel != 4 && panel != 5) { /* 4 = front ; 5 = back */
-               ALOGW("Unhandled panel spec\n");
-               return;
-       }
+       *panel = p;
+       *rotation = r;
 
-       /* Only deal with 90° rotations for now */
-       if (rotation < 0 || rotation > 7 || (rotation & 1)) {
-               ALOGW("Unhandled rotation spec\n");
-               return;
-       }
+       ALOGI("S%d PLD from sysfs: panel=%d, rotation=%d\n", s, p, r);
+
+       return 0;
+}
+
+
+static void decode_placement_information (int dev_num, int num_channels, int s)
+{
+       /*
+        * See if we have optional "physical location of device" ACPI tags.
+        * We're only interested in panel and rotation specifiers. Use the
+        * .panel and .rotation properties in priority, and the actual ACPI
+        * values as a second source.
+        */
+
+       int panel;
+       int rotation;
+
+       if (read_pld_from_properties(s, &panel, &rotation) &&
+               read_pld_from_sysfs(s, dev_num, &panel, &rotation))
+                       return; /* No PLD data available */
 
        /* Map that to field ordering and scaling mechanisms */
        setup_properties_from_pld(s, panel, rotation, num_channels);