static int es705_uart_boot_setup(struct es705_priv *es705) { u8 sbl_sync_cmd = ES705_SBL_SYNC_CMD; u8 sbl_boot_cmd = ES705_SBL_BOOT_CMD; u32 rspn = sbl_sync_cmd; const int match = 1; int rc; /* Detect BAUD RATE send SBL SYNC BYTE 0x00 */ dev_dbg(es705->dev, "%s(): write ES705_SBL_SYNC_CMD = 0x%02x\n", __func__, sbl_sync_cmd); rc = es705_uart_write_then_read(es705, &sbl_sync_cmd, 1, &rspn, match); if (rc < 0) { dev_err(es705->dev, "%s(): UART baud rate detection fail\n", __func__); goto es705_bootup_failed; } dev_dbg(es705->dev, "%s(): sbl sync ack = 0x%02x\n", __func__, rspn); es705->uart_fw_download_rate = 3; rc = es705_set_uart_baud_rate(es705); if (rc < 0) { dev_err(es705->dev, "%s(): uart baud rate set error\n", __func__); goto es705_bootup_failed; } es705_set_tty_baud_rate(es705->uart_fw_download_rate); /* SBL SYNC BYTE 0x00 */ dev_dbg(es705->dev, "%s(): write ES705_SBL_SYNC_CMD = 0x%02x\n", __func__, sbl_sync_cmd); rc = es705_uart_write_then_read(es705, &sbl_sync_cmd, 1, &rspn, match); if (rc < 0) { dev_err(es705->dev, "%s(): UART FW Download SBL SYNC fail\n", __func__); goto es705_bootup_failed; } dev_dbg(es705->dev, "%s(): sbl sync ack = 0x%02x\n", __func__, rspn); /* SBL BOOT BYTE 0x01 */ dev_dbg(es705->dev, "%s(): write ES705_SBL_BOOT_CMD = 0x%02x\n", __func__, sbl_boot_cmd); rspn = ES705_SBL_BOOT_ACK; rc = es705_uart_write_then_read(es705, &sbl_boot_cmd, 1, &rspn, match); if (rc < 0) { dev_err(es705->dev, "%s(): UART FW Download BOOT CMD fail\n", __func__); goto es705_bootup_failed; } dev_dbg(es705->dev, "%s(): sbl boot ack = 0x%02x\n", __func__, rspn); es705_bootup_failed: return rc; }
int es705_uart_fw_download(struct es705_priv *es705, int fw_type) { int rc; dev_info(es705_priv.dev, "%s(): ********* START %s FW Download\n", __func__, fw_type == VOICESENSE ? "VS" : "Standard"); rc = es705_uart_open(es705); if (rc) { dev_err(es705->dev, "%s(): uart open error\n", __func__); goto uart_open_error; } es705_set_tty_baud_rate(UART_DOWNLOAD_INITIAL_SYNC_BAUD_RATE_INDEX); rc = es705_uart_boot_setup(es705); if (rc < 0) { dev_err(es705->dev, "%s(): uart boot setup error\n", __func__); goto uart_download_error; } if (fw_type == VOICESENSE) rc = es705_uart_write(es705, (char *)es705->vs->data, es705->vs->size); else rc = es705_uart_write(es705, (char *)es705->standard->data, es705->standard->size); if (rc < 0) { dev_err(es705->dev, "%s(): uart %s image write fail\n", __func__, fw_type == VOICESENSE ? "vs" : "standard"); rc = -EIO; goto uart_download_error; } dev_info(es705->dev, "%s(): %s fw download done\n", __func__, fw_type == VOICESENSE ? "vs" : "standard"); rc = es705_uart_boot_finish(es705); if (rc < 0) dev_err(es705->dev, "%s(): uart boot finish error\n", __func__); uart_download_error: es705_uart_close(es705); uart_open_error: dev_info(es705_priv.dev, "%s(): ********* END %s FW Download\n", __func__, fw_type == VOICESENSE ? "VS" : "Standard"); return rc; }
int es705_uart_open(struct es705_priv *es705) { long err = 0; struct file *fp = NULL; unsigned long timeout = jiffies + msecs_to_jiffies(250); int attempt = 0; dev_dbg(es705->dev, "%s(): start open tty\n", __func__); if (es705->uart_state == UART_OPEN) es705_uart_close(es705); /* SAMSUNG - uart_gpio control */ if (es705->pdata->uart_gpio != -1) gpio_set_value(es705->pdata->uart_gpio, 1); /* try to probe tty node every 50 ms for 250 ms */ do { if (attempt > 0) msleep(50); dev_dbg(es705->dev, "%s(): probing for tty on %s (attempt %d)\n", __func__, UART_TTY_DEVICE_NODE, ++attempt); fp = filp_open(UART_TTY_DEVICE_NODE, O_RDWR | O_NONBLOCK | O_NOCTTY, 0); err = PTR_ERR(fp); } while (time_before(jiffies, timeout) && err == -ENOENT); if (IS_ERR_OR_NULL(fp)) { dev_err(es705->dev, "%s(): UART device node open failed\n", __func__); return -ENODEV; } /* device node found */ dev_dbg(es705->dev, "%s(): successfully opened tty\n", __func__); /* set uart_dev members */ es705_priv.uart_dev.file = fp; es705_priv.uart_dev.tty = ((struct tty_file_private *)fp->private_data)->tty; /* set baudrate to FW baud (common case) */ es705_set_tty_baud_rate(es705->uart_fw_download_rate); es705->uart_state = UART_OPEN; return 0; }