int hw_fd = -1;
int rc = -1;
- if(pdata == NULL)
+ if(pdata == NULL || pdata->ops == NULL)
return -1;
- hw_node = yamaha_mc1n2_audio_get_hw_node(pdata);
+ hw_node = pdata->ops->hw_node;
if(hw_node == NULL) {
LOGE("%s: error, missing hw_node!", __func__);
return -1;
}
- hw_fd = open(hw_node, O_RDWR);
- if(hw_fd < 0) {
- LOGE("%s: error, unable to open hw_node (fd is %d)!", __func__, hw_fd);
- return -1;
+ if(pdata->ops->hw_fd <= 0) {
+ hw_fd = open(hw_node, O_RDWR);
+ if(hw_fd < 0) {
+ LOGE("%s: error, unable to open hw_node (fd is %d)!", __func__, hw_fd);
+ return -1;
+ }
+
+ pdata->ops->hw_fd = hw_fd;
}
- rc = ioctl(hw_fd, command, hw_ctrl);
+ rc = ioctl(pdata->ops->hw_fd, command, hw_ctrl);
if(rc < 0) {
LOGE("%s: error, ioctl on hw_node failed (rc is %d)!", __func__, rc);
return -1;
}
- close(hw_fd);
-
return rc;
}
return -1;
pdata = yamaha_mc1n2_audio_platform_get(device_name);
- if(pdata == NULL) {
+ if(pdata == NULL || pdata->ops == NULL) {
LOGE("Unable to find requested platform: %s", device_name);
return -1;
}
+ pdata->ops->hw_fd = -1;
+
*pdata_p = pdata;
return 0;
int yamaha_mc1n2_audio_stop(struct yamaha_mc1n2_audio_pdata *pdata)
{
- if(pdata == NULL)
+ LOGD("%s()", __func__);
+
+ if(pdata == NULL || pdata->ops == NULL)
return -1;
- LOGD("%s()", __func__);
+ if(pdata->ops->hw_fd >= 0) {
+ close(pdata->ops->hw_fd);
+ }
return 0;
}