#include <linux/ioctl.h>
-#define LOG_TAG "YAMAHA-MC1N2-AUDIO"
+#define LOG_TAG "Yamaha-MC1N2-Audio"
#include <cutils/log.h>
#include <yamaha-mc1n2-audio.h>
+struct yamaha_mc1n2_audio_pdata *yamaha_mc1n2_audio_platforms[] = {
+ &galaxys2_pdata,
+};
+
+int yamaha_mc1n2_audio_platforms_count = sizeof(yamaha_mc1n2_audio_platforms) /
+ sizeof(struct yamaha_mc1n2_audio_pdata *);
+
/*
* IOCTL
*/
return -1;
}
- rc = ioctl(hw_fd, command, &hw_ctrl);
+ rc = ioctl(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;
}
}
/*
- * Values configuration
+ * Routines
*/
-int yamaha_mc1n2_audio_set_hw_node(struct yamaha_mc1n2_audio_pdata *pdata, char *node)
+int yamaha_mc1n2_audio_routine_init(struct yamaha_mc1n2_audio_pdata *pdata)
{
- if(pdata == NULL || node == NULL)
+ struct yamaha_mc1n2_audio_routine_init *routine = NULL;
+ int rc = -1;
+
+ if(pdata == NULL || pdata->ops == NULL)
+ return -1;
+
+ routine = pdata->ops->routine.init;
+ if(routine == NULL)
return -1;
- if(pdata->hw_node != NULL) {
- LOGD("%s: previous node was: %s", __func__, pdata->hw_node);
- free(pdata->hw_node);
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_DAC,
+ &routine->dac_info, 0x07);
+ if(rc < 0) {
+ LOGE("SET_DAC IOCTL failed, aborting!");
+ return -1;
}
- pdata->hw_node = strdup(node);
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_ADC,
+ &routine->adc_info, 0x07);
+ if(rc < 0) {
+ LOGE("SET_ADC IOCTL failed, aborting!");
+ return -1;
+ }
- LOGD("%s: setting node to: %s", __func__, pdata->hw_node);
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_SP,
+ &routine->sp_info, 0x00);
+ if(rc < 0) {
+ LOGE("SET_SP IOCTL failed, aborting!");
+ return -1;
+ }
+
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_PDM,
+ &routine->pdm_info, 0x7f);
+ if(rc < 0) {
+ LOGE("SET_PDM IOCTL failed, aborting!");
+ return -1;
+ }
+
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_DNG,
+ &routine->dng_info, 0x3f3f3f);
+ if(rc < 0) {
+ LOGE("SET_DNG IOCTL failed, aborting!");
+ return -1;
+ }
+
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_SYSEQ,
+ &routine->syseq_info, 0x03);
+ if(rc < 0) {
+ LOGE("SET_SYSEQ IOCTL failed, aborting!");
+ return -1;
+ }
return 0;
}
+int yamaha_mc1n2_audio_routine_route_init(struct yamaha_mc1n2_audio_pdata *pdata)
+{
+ struct yamaha_mc1n2_audio_routine_route_init *routine = NULL;
+ int rc = -1;
+
+ if(pdata == NULL || pdata->ops == NULL)
+ return -1;
+
+ routine = pdata->ops->routine.route_init;
+ if(routine == NULL)
+ return -1;
+
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_PATH,
+ &routine->path_info, 0x00);
+ if(rc < 0) {
+ LOGE("SET_PATH IOCTL failed, aborting!");
+ return -1;
+ }
+
+ rc = yamaha_mc1n2_audio_ioctl_set_ctrl(pdata, MCDRV_SET_DAC,
+ &routine->dac_info, 0x07);
+ if(rc < 0) {
+ LOGE("SET_DAC IOCTL failed, aborting!");
+ return -1;
+ }
+
+ return 0;
+}
+
+/*
+ * Values configuration
+ */
+
char *yamaha_mc1n2_audio_get_hw_node(struct yamaha_mc1n2_audio_pdata *pdata)
{
if(pdata == NULL)
return NULL;
- return pdata->hw_node;
+ return pdata->ops->hw_node;
}
/*
* Init/Deinit
*/
-int yamaha_mc1n2_audio_init(struct yamaha_mc1n2_audio_pdata **pdata_p)
+struct yamaha_mc1n2_audio_pdata *yamaha_mc1n2_audio_platform_get(
+ char *device_name)
+{
+ int i;
+
+ if(device_name == NULL)
+ return NULL;
+
+ LOGD("Found %d registered platforms",
+ yamaha_mc1n2_audio_platforms_count);
+
+ for(i=0 ; i < yamaha_mc1n2_audio_platforms_count ; i++) {
+ if(yamaha_mc1n2_audio_platforms[i] != NULL &&
+ yamaha_mc1n2_audio_platforms[i]->name != NULL) {
+ if(strcmp(yamaha_mc1n2_audio_platforms[i]->name, device_name) == 0) {
+ return yamaha_mc1n2_audio_platforms[i];
+ }
+ }
+ }
+
+ return NULL;
+}
+
+
+int yamaha_mc1n2_audio_start(struct yamaha_mc1n2_audio_pdata **pdata_p,
+ char *device_name)
{
struct yamaha_mc1n2_audio_pdata *pdata = NULL;
+ int rc;
- if(pdata_p == NULL)
+ if(pdata_p == NULL || device_name == NULL)
return -1;
- pdata = calloc(1, sizeof(struct yamaha_mc1n2_audio_pdata));
+ pdata = yamaha_mc1n2_audio_platform_get(device_name);
+ if(pdata == NULL) {
+ LOGE("Unable to find requested platform: %s", device_name);
+ return -1;
+ }
- yamaha_mc1n2_audio_set_hw_node(pdata, HW_NODE_DEFAULT);
+ *pdata_p = pdata;
return 0;
}
-int yamaha_mc1n2_audio_deinit(struct yamaha_mc1n2_audio_pdata *pdata)
+int yamaha_mc1n2_audio_stop(struct yamaha_mc1n2_audio_pdata *pdata)
{
if(pdata == NULL)
return -1;
- if(pdata->hw_node)
- free(pdata->hw_node);
-
- memset(pdata, 0, sizeof(struct yamaha_mc1n2_audio_pdata));
-
- free(pdata);
-
return 0;
}