2 * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <sys/types.h>
26 #include <linux/ioctl.h>
28 #define LOG_TAG "YAMAHA-MC1N2-AUDIO"
29 #include <cutils/log.h>
31 #include <yamaha-mc1n2-audio.h>
37 int yamaha_mc1n2_audio_ioctl(struct yamaha_mc1n2_audio_pdata *pdata,
38 int command, struct mc1n2_ctrl_args *hw_ctrl)
47 hw_node = yamaha_mc1n2_audio_get_hw_node(pdata);
49 LOGE("%s: error, missing hw_node!", __func__);
53 hw_fd = open(hw_node, O_RDWR);
55 LOGE("%s: error, unable to open hw_node (fd is %d)!", __func__, hw_fd);
59 rc = ioctl(hw_fd, command, &hw_ctrl);
61 LOGE("%s: error, ioctl on hw_node failed (rc is %d)!", __func__, rc);
68 int yamaha_mc1n2_audio_ioctl_set_ctrl(struct yamaha_mc1n2_audio_pdata *pdata,
69 unsigned long command, void *data, unsigned long update_info)
71 struct mc1n2_ctrl_args hw_ctrl;
76 memset(&hw_ctrl, 0, sizeof(hw_ctrl));
77 hw_ctrl.dCmd = command;
79 hw_ctrl.dPrm = update_info;
81 return yamaha_mc1n2_audio_ioctl(pdata, MC1N2_IOCTL_SET_CTRL, &hw_ctrl);
84 int yamaha_mc1n2_audio_ioctl_notify(struct yamaha_mc1n2_audio_pdata *pdata,
85 unsigned long command)
87 struct mc1n2_ctrl_args hw_ctrl;
92 memset(&hw_ctrl, 0, sizeof(hw_ctrl));
93 hw_ctrl.dCmd = command;
95 return yamaha_mc1n2_audio_ioctl(pdata, MC1N2_IOCTL_NOTIFY, &hw_ctrl);
99 * Values configuration
102 int yamaha_mc1n2_audio_set_hw_node(struct yamaha_mc1n2_audio_pdata *pdata, char *node)
104 if(pdata == NULL || node == NULL)
107 if(pdata->hw_node != NULL) {
108 LOGD("%s: previous node was: %s", __func__, pdata->hw_node);
109 free(pdata->hw_node);
112 pdata->hw_node = strdup(node);
114 LOGD("%s: setting node to: %s", __func__, pdata->hw_node);
119 char *yamaha_mc1n2_audio_get_hw_node(struct yamaha_mc1n2_audio_pdata *pdata)
124 return pdata->hw_node;
131 int yamaha_mc1n2_audio_init(struct yamaha_mc1n2_audio_pdata **pdata_p)
133 struct yamaha_mc1n2_audio_pdata *pdata = NULL;
138 pdata = calloc(1, sizeof(struct yamaha_mc1n2_audio_pdata));
140 yamaha_mc1n2_audio_set_hw_node(pdata, HW_NODE_DEFAULT);
145 int yamaha_mc1n2_audio_deinit(struct yamaha_mc1n2_audio_pdata *pdata)
151 free(pdata->hw_node);
153 memset(pdata, 0, sizeof(struct yamaha_mc1n2_audio_pdata));