static int __init hisi_clkmbox_init(void) { int ret = 0; mbox_clk = kzalloc(sizeof(*mbox_clk), GFP_KERNEL); if (!mbox_clk) { pr_err("[%s] fail to alloc mbox_clk!\n", __func__); ret = -ENOMEM; goto err; } /* get mailbox to communicate with lpm3 */ mbox_clk->mbox = hisi_mbox_get(HISI_MAILBOX_RP_LPM3, NULL); if (!mbox_clk->mbox) { pr_err("[%s] fail to get mbox!\n", __func__); ret = -ENODEV; goto err_mbox; } mailbox_disable = 0; register_pm_notifier(&mailbox_pm_notif_block); return ret; err_mbox: kfree(mbox_clk); mbox_clk = NULL; err: return ret; }
/* hisi adc init function */ static int __init hisi_adc_driver_init(void) { int ret = 0; hisi_adc_dev = kzalloc(sizeof(*hisi_adc_dev), GFP_KERNEL); if (!hisi_adc_dev) { pr_err("%s: fail to alloc adc dev!\n", MODULE_NAME); ret = -ENOMEM; goto err_adc_dev; } hisi_adc_dev->nb = kzalloc(sizeof(struct notifier_block), GFP_KERNEL); if (!hisi_adc_dev->nb) { pr_err("%s: fail to alloc notifier_block!\n", MODULE_NAME); ret = -ENOMEM; goto err_adc_nb; } hisi_adc_dev->nb->next = NULL; hisi_adc_dev->nb->notifier_call = adc_dev_notifier; hisi_adc_dev->mbox = hisi_mbox_get(HISI_MAILBOX_RP_LPM3, hisi_adc_dev->nb); if (!hisi_adc_dev->mbox) { pr_err("%s: fail to get mail box!\n", MODULE_NAME); ret = -ENODEV; goto err_get_mbox; } hisi_adc_dev->tx_msg[ADC_IPC_CMD_TYPE] = ADC_IPC_DATA; hisi_adc_dev->tx_msg[ADC_IPC_CMD_CHANNEL] = ADC_RESULT_ERR; mutex_init(&hisi_adc_dev->mutex); init_completion(&hisi_adc_dev->completion); adc_init_device_debugfs(); pr_info("%s: init ok!\n", MODULE_NAME); return ret; err_get_mbox: kfree(hisi_adc_dev->nb); hisi_adc_dev->nb = NULL; err_adc_nb: kfree(hisi_adc_dev); hisi_adc_dev = NULL; err_adc_dev: return ret; }
static int mbox_debugfs_mbox_get(char *name) { struct notifier_block *nb = NULL; struct hisi_mbox *mbox = NULL; char *rp_name = NULL; int i; if (!name) return -EINVAL; for (i = 0; (debugfs_mboxes[i].mbox) && (i < DEBUGFS_MBOXES_NUM); i++) ; if (i >= DEBUGFS_MBOXES_NUM) return -ENOMEM; nb = kmalloc(sizeof(*nb), GFP_KERNEL); if (!nb) return -ENOMEM; nb->next = NULL; nb->notifier_call = mbox_debugfs_notifier; mbox = hisi_mbox_get(name, nb); if (!mbox) { kfree(nb); return -ENODEV; } rp_name = kmalloc(sizeof(char) * (strlen(name) + 1), GFP_KERNEL); if (!rp_name) { hisi_mbox_put(&mbox); kfree(nb); return -ENOMEM; } strncpy(rp_name, name, strlen(name) + 1); *(rp_name + strlen(name)) = '\0'; MBOX_DEBUG_ON(mbox); debugfs_mboxes[i].mbox = mbox; debugfs_mboxes[i].nb = nb; debugfs_mboxes[i].rp_name = rp_name; debugfs_mboxes[i].initialized = 0; return 0; }
int inputhub_mcu_connect( void ) { //connect to inputhub_route api_inputhub_mcu_recv=inputhub_route_recv_mcu_data;//should supply an interface //connect to mcu hwlog_info("----%s--->\n",__func__); nb = (struct notifier_block *)kmalloc(sizeof(struct notifier_block), GFP_KERNEL); if (!nb) return -ENOMEM; nb->next = NULL; nb->notifier_call = mbox_recv_notifier; if (!(mbox = hisi_mbox_get(HISI_MAILBOX_RP_IOM3, nb))) { hwlog_err("failed to get mailbox in %s\n", __func__); kfree((void *)nb); return -ENODEV; } mbox->nb=nb; return 0; }
void boot_iom3(void) { struct hisi_mbox_task *tx_task = NULL; if (!(lpm3_mbox = hisi_mbox_get(HISI_MAILBOX_RP_LPM3, NULL))) { hwlog_err("failed to get mailbox in %s\n", __func__); return; } tx_task = hisi_mbox_task_alloc(lpm3_mbox, HISI_MAILBOX_RP_LPM3, &g_boot_iom3, 1, 1, inputhub_power_on_complete, NULL); if(!tx_task) { hwlog_err("failed to alloc task %s\n", __func__); return; } if (hisi_mbox_msg_send_async(lpm3_mbox,tx_task) != 0) { hwlog_err("hisi_mbox_msg_send_async error in %s\n", __func__); } }