API for setting and reading UMIP OEM Factory flag
authorDavid Castelain <davidx.castelain@intel.com>
Fri, 11 May 2012 17:25:22 +0000 (19:25 +0200)
committerbuildbot <buildbot@intel.com>
Thu, 7 Jun 2012 13:21:50 +0000 (06:21 -0700)
BZ: 35509

API creation for setting and reading UMIP OEM Factory flag in intel_mid_umip.

Change-Id: Ie316a74e99517947c59449bd55c4af29db8f63d5
Signed-off-by: David Castelain <davidx.castelain@intel.com>
Reviewed-on: http://android.intel.com:8080/51533
Reviewed-by: Sahukar, Surya P <surya.p.sahukar@intel.com>
Tested-by: Afantenos, Marie CecileX <marie.cecilex.afantenos@intel.com>
Reviewed-by: Romieu, Benoit <benoit.romieu@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
drivers/platform/x86/intel_mid_umip.c

index 2be9afd..b2e7fb4 100644 (file)
 #include <linux/init.h>
 #include <asm/intel_scu_ipc.h>
 #include <linux/platform_device.h>
+#include <asm/intel-mid.h>
 
-#define USB_HOST_ENABLE_TIMEOUT_INFINITE      0x3F
-#define USB_HOST_ENABLE_TIMEOUT_THREE         0x1B
-#define USB_HOST_ENABLE_TIMEOUT_ZERO          0X00
-#define USB_ENABLE_UMIP_OFFSET                0x400
-#define MAX_USB_TIMEOUT_LEN                    14
-#define MAX_NUM_TIMEOUTS                       3
-#define ERROR_MSG                              "Could not read right value"
+#define USB_HOST_ENABLE_TIMEOUT_INFINITE    0x3F
+#define USB_HOST_ENABLE_TIMEOUT_THREE       0x1B
+#define USB_HOST_ENABLE_TIMEOUT_ZERO        0X00
+#define USB_ENABLE_UMIP_OFFSET              0x400
+#define MAX_USB_TIMEOUT_LEN                 14
+#define MAX_NUM_TIMEOUTS                    3
+#define FACTORY_UMIP_OFFSET                 0xE00
+#define FACTORY_BIT_OFFSET                  0
+
+static struct platform_device *umip_mid_pdev;
+
+/*
+       The "current Factory UMIP" shows the current value of
+       the variable.
+*/
+
+static ssize_t Factory_UMIP_show(struct device *dev,
+                               struct device_attribute *attr, char *buffer)
+{
+       int ret;
+       u8 data_read;
+
+       if (intel_mid_identify_cpu() == INTEL_MID_CPU_CHIP_PENWELL) {
+               ret = intel_scu_ipc_read_mip(&data_read,
+                                               1,
+                                               FACTORY_UMIP_OFFSET,
+                                               0);
+               if (ret) {
+                       pr_err("Could not read to UMIP for Factory\n");
+                       return -EBUSY;
+               }
+       }
+
+       return sprintf(buffer, "%d\n",
+                               (data_read >> FACTORY_BIT_OFFSET) & 0x01);
+}
+
+ssize_t Factory_UMIP_store(struct device *dev,
+                                       struct device_attribute *attr,
+                                       const char *buffer, size_t count)
+{
+       int ret = 0;
+       u8 data_write;
+       u8 yes;
+       u8 no;
+       bool bv;
+
+       if (strlen(buffer) != 2) {
+               pr_err("The length must be 1\n");
+               ret = -EINVAL;
+               goto error;
+       }
+
+       ret = strtobool(buffer, &bv);
+       if (ret) {
+               pr_err("Not expected value [Y|y|1|N|n|0]\n");
+               goto error;
+       }
+
+       if (intel_mid_identify_cpu() == INTEL_MID_CPU_CHIP_PENWELL) {
+               ret = intel_scu_ipc_read_mip(&data_write,
+                                               1,
+                                               FACTORY_UMIP_OFFSET,
+                                               0);
+               data_write &= ~(1 << FACTORY_BIT_OFFSET);
+               data_write |= bv;
+
+               ret = intel_scu_ipc_write_umip(&data_write,
+                                               1,
+                                               FACTORY_UMIP_OFFSET);
+
+               if (ret) {
+                       pr_err("Could not write to UMIP for Factory\n");
+                       goto error;
+               }
+       }
+
+       return count;
+
+error:
+       return ret;
+}
 
 struct usb_timeout {
        char name[MAX_USB_TIMEOUT_LEN];
@@ -44,7 +120,6 @@ static struct
         {"zeroseconds", USB_HOST_ENABLE_TIMEOUT_ZERO}
 };
 
-static struct platform_device *umip_mid_pdev;
 /*
         The "availabe usb host enable timeouts" file where a static variable
         is read from and written to.
@@ -75,7 +150,7 @@ static ssize_t usb_host_enable_timeout_show(struct device *dev,
                                        USB_ENABLE_UMIP_OFFSET,
                                        0);
        if (ret_ipc)
-               pr_err("Could not write to UMIP USB Host Enable\n");
+               pr_err("Could not read to UMIP USB Host Enable\n");
 
        for (i = 0; i < MAX_NUM_TIMEOUTS; i++) {
                if (data_read ==
@@ -87,7 +162,7 @@ static ssize_t usb_host_enable_timeout_show(struct device *dev,
        }
 
        if (i == MAX_NUM_TIMEOUTS)
-               return sprintf(buffer, "%s\n", ERROR_MSG);
+               return sprintf(buffer, "%s\n", "Could not read right value");
        else
                return sprintf(buffer, "%s\n", &timeout);
 }
@@ -132,6 +207,8 @@ ssize_t usb_host_enable_timeout_store(struct device *dev,
 }
 
 /* Attach the sysfs write method */
+DEVICE_ATTR(Factory_UMIP, S_IRUGO|S_IWUSR,
+               Factory_UMIP_show, Factory_UMIP_store);
 DEVICE_ATTR(available_timeouts, S_IRUGO,
                available_usb_host_enable_timeouts_show, NULL);
 DEVICE_ATTR(current_timeout, S_IRUGO|S_IWUSR,
@@ -139,6 +216,7 @@ DEVICE_ATTR(current_timeout, S_IRUGO|S_IWUSR,
 
 /* Attribute Descriptor */
 static struct attribute *umip_mid_attrs[] = {
+               &dev_attr_Factory_UMIP.attr,
                &dev_attr_available_timeouts.attr,
                &dev_attr_current_timeout.attr,
                NULL