]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - rpmsg/hwspinlock.git/blobdiff - drivers/soc/ti/wkup_m3_ipc.c
soc: ti: wkup_m3_ipc: Add support for i2c voltage scaling
[rpmsg/hwspinlock.git] / drivers / soc / ti / wkup_m3_ipc.c
index f5cb8c0af09f3ab8ade4443ada270bf1f1eefa92..a32412906b3ae358cde7c5d02f895e364868f12b 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #include <linux/err.h>
+#include <linux/firmware.h>
 #include <linux/kernel.h>
 #include <linux/kthread.h>
 #include <linux/interrupt.h>
 #define M3_FW_VERSION_MASK             0xffff
 #define M3_WAKE_SRC_MASK               0xff
 
+#define IPC_MEM_TYPE_SHIFT             (0x0)
+#define IPC_MEM_TYPE_MASK              (0x7 << 0)
+#define IPC_VTT_STAT_SHIFT             (0x3)
+#define IPC_VTT_STAT_MASK              (0x1 << 3)
+#define IPC_VTT_GPIO_PIN_SHIFT         (0x4)
+#define IPC_VTT_GPIO_PIN_MASK          (0x3f << 4)
+#define IPC_IO_ISOLATION_STAT_SHIFT    (10)
+#define IPC_IO_ISOLATION_STAT_MASK     (0x1 << 10)
+
 #define M3_STATE_UNKNOWN               0
 #define M3_STATE_RESET                 1
 #define M3_STATE_INITED                        2
 #define M3_STATE_MSG_FOR_LP            3
 #define M3_STATE_MSG_FOR_RESET         4
 
+#define WKUP_M3_SD_FW_MAGIC            0x570C
+
+#define WKUP_M3_DMEM_START             0x80000
+#define WKUP_M3_AUXDATA_OFFSET         0x1000
+#define WKUP_M3_AUXDATA_SIZE           0xFF
+
 static struct wkup_m3_ipc *m3_ipc_state;
 
 static const struct wkup_m3_wakeup_src wakeups[] = {
@@ -73,6 +89,80 @@ static const struct wkup_m3_wakeup_src wakeups[] = {
        {.irq_nr = 0,   .src = "Unknown"},
 };
 
+/**
+ * wkup_m3_copy_aux_data - Copy auxiliary data to special region of m3 dmem
+ * @data - pointer to data
+ * @sz - size of data to copy (limit 256 bytes)
+ *
+ * Copies any additional blob of data to the wkup_m3 dmem to be used by the
+ * firmware
+ */
+static unsigned long wkup_m3_copy_aux_data(struct wkup_m3_ipc *m3_ipc,
+                                          const void *data, int sz)
+{
+       unsigned long aux_data_dev_addr;
+       void *aux_data_addr;
+
+       aux_data_dev_addr = WKUP_M3_DMEM_START + WKUP_M3_AUXDATA_OFFSET;
+       aux_data_addr = rproc_da_to_va(m3_ipc->rproc,
+                                      aux_data_dev_addr,
+                                      WKUP_M3_AUXDATA_SIZE);
+       memcpy(aux_data_addr, data, sz);
+
+       return WKUP_M3_AUXDATA_OFFSET;
+}
+
+static void wkup_m3_scale_data_fw_cb(const struct firmware *fw, void *context)
+{
+       unsigned long val, aux_base;
+       struct wkup_m3_scale_data_header hdr;
+       struct wkup_m3_ipc *m3_ipc = context;
+       struct device *dev = m3_ipc->dev;
+
+       if (!fw) {
+               dev_err(dev, "Voltage scale fw name given but file missing.\n");
+               return;
+       }
+
+       memcpy(&hdr, fw->data, sizeof(hdr));
+
+       if (hdr.magic != WKUP_M3_SD_FW_MAGIC) {
+               dev_err(dev, "PM: Voltage Scale Data binary does not appear valid.\n");
+               goto release_sd_fw;
+       }
+
+       aux_base = wkup_m3_copy_aux_data(m3_ipc, fw->data + sizeof(hdr),
+                                        fw->size - sizeof(hdr));
+
+       val = (aux_base + hdr.sleep_offset);
+       val |= ((aux_base + hdr.wake_offset) << 16);
+
+       m3_ipc->volt_scale_offsets = val;
+
+release_sd_fw:
+       release_firmware(fw);
+};
+
+static int wkup_m3_init_scale_data(struct wkup_m3_ipc *m3_ipc,
+                                  struct device *dev)
+{
+       int ret = 0;
+
+       /*
+        * If no name is provided, user has already been warned, pm will
+        * still work so return 0
+        */
+
+       if (!m3_ipc->sd_fw_name)
+               return ret;
+
+       ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
+                                     m3_ipc->sd_fw_name, dev, GFP_ATOMIC,
+                                     m3_ipc, wkup_m3_scale_data_fw_cb);
+
+       return ret;
+}
+
 static void am33xx_txev_eoi(struct wkup_m3_ipc *m3_ipc)
 {
        writel(AM33XX_M3_TXEV_ACK,
@@ -137,6 +227,7 @@ static irqreturn_t wkup_m3_txev_handler(int irq, void *ipc_data)
                }
 
                m3_ipc->state = M3_STATE_INITED;
+               wkup_m3_init_scale_data(m3_ipc, dev);
                complete(&m3_ipc->sync_complete);
                break;
        case M3_STATE_MSG_FOR_RESET:
@@ -222,6 +313,17 @@ static int wkup_m3_is_available(struct wkup_m3_ipc *m3_ipc)
                (m3_ipc->state != M3_STATE_UNKNOWN));
 }
 
+static void wkup_m3_set_vtt_gpio(struct wkup_m3_ipc *m3_ipc, int gpio)
+{
+       m3_ipc->vtt_conf = (1 << IPC_VTT_STAT_SHIFT) |
+                           (gpio << IPC_VTT_GPIO_PIN_SHIFT);
+}
+
+static void wkup_m3_set_io_isolation(struct wkup_m3_ipc *m3_ipc)
+{
+       m3_ipc->isolation_conf = (1 << IPC_IO_ISOLATION_STAT_SHIFT);
+}
+
 /* Public functions */
 /**
  * wkup_m3_set_mem_type - Pass wkup_m3 which type of memory is in use
@@ -283,12 +385,15 @@ static int wkup_m3_prepare_low_power(struct wkup_m3_ipc *m3_ipc, int state)
        switch (state) {
        case WKUP_M3_DEEPSLEEP:
                m3_power_state = IPC_CMD_DS0;
+               wkup_m3_ctrl_ipc_write(m3_ipc, m3_ipc->volt_scale_offsets, 5);
                break;
        case WKUP_M3_STANDBY:
                m3_power_state = IPC_CMD_STANDBY;
+               wkup_m3_ctrl_ipc_write(m3_ipc, DS_IPC_DEFAULT, 5);
                break;
        case WKUP_M3_IDLE:
                m3_power_state = IPC_CMD_IDLE;
+               wkup_m3_ctrl_ipc_write(m3_ipc, DS_IPC_DEFAULT, 5);
                break;
        default:
                return 1;
@@ -297,11 +402,11 @@ static int wkup_m3_prepare_low_power(struct wkup_m3_ipc *m3_ipc, int state)
        /* Program each required IPC register then write defaults to others */
        wkup_m3_ctrl_ipc_write(m3_ipc, m3_ipc->resume_addr, 0);
        wkup_m3_ctrl_ipc_write(m3_ipc, m3_power_state, 1);
-       wkup_m3_ctrl_ipc_write(m3_ipc, m3_ipc->mem_type, 4);
-
+       wkup_m3_ctrl_ipc_write(m3_ipc, m3_ipc->mem_type |
+                              m3_ipc->vtt_conf |
+                              m3_ipc->isolation_conf, 4);
        wkup_m3_ctrl_ipc_write(m3_ipc, DS_IPC_DEFAULT, 2);
        wkup_m3_ctrl_ipc_write(m3_ipc, DS_IPC_DEFAULT, 3);
-       wkup_m3_ctrl_ipc_write(m3_ipc, DS_IPC_DEFAULT, 5);
        wkup_m3_ctrl_ipc_write(m3_ipc, DS_IPC_DEFAULT, 6);
        wkup_m3_ctrl_ipc_write(m3_ipc, DS_IPC_DEFAULT, 7);
 
@@ -433,12 +538,13 @@ static void wkup_m3_rproc_boot_thread(struct wkup_m3_ipc *m3_ipc)
 static int wkup_m3_ipc_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
-       int irq, ret;
+       int irq, ret, temp;
        phandle rproc_phandle;
        struct rproc *m3_rproc;
        struct resource *res;
        struct task_struct *task;
        struct wkup_m3_ipc *m3_ipc;
+       struct device_node *np = dev->of_node;
 
        m3_ipc = devm_kzalloc(dev, sizeof(*m3_ipc), GFP_KERNEL);
        if (!m3_ipc)
@@ -498,6 +604,23 @@ static int wkup_m3_ipc_probe(struct platform_device *pdev)
 
        m3_ipc->ops = &ipc_ops;
 
+       if (of_find_property(np, "ti,needs-vtt-toggle", NULL) &&
+           !(of_property_read_u32(np, "ti,vtt-gpio-pin", &temp))) {
+               if (temp >= 0 && temp <= 31)
+                       wkup_m3_set_vtt_gpio(m3_ipc, temp);
+               else
+                       dev_warn(dev, "Invalid VTT GPIO(%d) pin\n", temp);
+       }
+
+       if (of_find_property(np, "ti,set-io-isolation", NULL))
+               wkup_m3_set_io_isolation(m3_ipc);
+
+       ret = of_property_read_string(np, "ti,scale-data-fw",
+                                     &m3_ipc->sd_fw_name);
+       if (ret) {
+               dev_dbg(dev, "Voltage scaling data blob not provided from DT.\n");
+       };
+
        /*
         * Wait for firmware loading completion in a thread so we
         * can boot the wkup_m3 as soon as it's ready without holding