| /* |
| * driver/muic/muic_sysfs.c - micro USB switch device driver |
| * |
| * Copyright (C) 2015 Samsung Electronics |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License as published by |
| * the Free Software Foundation; either version 2 of the License, or |
| * (at your option) any later version. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| * |
| * You should have received a copy of the GNU General Public License |
| * along with this program; if not, write to the Free Software |
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| * |
| */ |
| #define pr_fmt(fmt) "[MUIC] " fmt |
| |
| #include <linux/types.h> |
| #include <linux/device.h> |
| #include <linux/delay.h> |
| #include <linux/sec_sysfs.h> |
| #include <linux/muic/muic_interface.h> |
| #include <linux/muic/muic_sysfs.h> |
| #include <linux/sec_ext.h> |
| #include <linux/sec_batt.h> |
| #include "../battery_v2/include/sec_charging_common.h" |
| |
| static ssize_t muic_sysfs_show_uart_en(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| int ret = 0; |
| |
| if (!muic_pdata->is_rustproof) { |
| pr_info("%s UART ENABLE\n", __func__); |
| ret = sprintf(buf, "1\n"); |
| } else { |
| pr_info("%s UART DISABLE\n", __func__); |
| ret = sprintf(buf, "0\n"); |
| } |
| |
| return ret; |
| } |
| |
| static ssize_t muic_sysfs_set_uart_en(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| |
| if (!strncmp(buf, "1", 1)) |
| muic_pdata->is_rustproof = false; |
| else if (!strncmp(buf, "0", 1)) |
| muic_pdata->is_rustproof = true; |
| else |
| pr_info("%s invalid value\n", __func__); |
| |
| pr_info("%s uart_en(%d)\n", |
| __func__, !muic_pdata->is_rustproof); |
| |
| return count; |
| } |
| |
| static ssize_t muic_sysfs_show_uart_sel(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| const char *mode = "UNKNOWN\n"; |
| |
| switch (muic_pdata->uart_path) { |
| case MUIC_PATH_UART_AP: |
| mode = "AP\n"; |
| break; |
| case MUIC_PATH_UART_CP: |
| mode = "CP\n"; |
| break; |
| default: |
| break; |
| } |
| |
| pr_info("%s %s", __func__, mode); |
| return snprintf(buf, strlen(mode) + 1, "%s", mode); |
| } |
| |
| static ssize_t muic_sysfs_set_uart_sel(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| |
| if (!strncasecmp(buf, "AP", 2)) |
| muic_pdata->uart_path = MUIC_PATH_UART_AP; |
| else if (!strncasecmp(buf, "CP", 2)) |
| muic_pdata->uart_path = MUIC_PATH_UART_CP; |
| else |
| pr_warn("%s invalid value\n", __func__); |
| |
| if (muic_if->set_switch_to_uart) |
| muic_if->set_switch_to_uart(muic_pdata->drv_data); |
| |
| pr_info("%s %s\n", __func__, buf); |
| |
| return count; |
| } |
| |
| static ssize_t muic_sysfs_show_usb_sel(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| return sprintf(buf, "PDA\n"); |
| } |
| |
| static ssize_t muic_sysfs_set_usb_sel(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| return count; |
| } |
| |
| static ssize_t muic_sysfs_show_usb_en(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| |
| return sprintf(buf, "%s attached_dev = %d\n", |
| __func__, muic_pdata->attached_dev); |
| } |
| |
| static ssize_t muic_sysfs_set_usb_en(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| muic_attached_dev_t new_dev = ATTACHED_DEV_USB_MUIC; |
| |
| if (!strncasecmp(buf, "1", 1)) |
| muic_core_handle_attach(muic_pdata, new_dev, 0, 0); |
| else if (!strncasecmp(buf, "0", 1)) |
| muic_core_handle_detach(muic_pdata); |
| else |
| pr_info("%s invalid value\n", __func__); |
| |
| pr_info("%s attached_dev(%d)\n", |
| __func__, muic_pdata->attached_dev); |
| |
| return count; |
| } |
| |
| static ssize_t muic_sysfs_show_adc(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| |
| int ret; |
| |
| #if IS_ENABLED(CONFIG_MUIC_SYSFS_SHOW_REFRESH_ADC) |
| int is_afc_muic_ready; |
| #if IS_ENABLED(CONFIG_MUIC_SUPPORT_CCIC) |
| /* TODO: NOTE: There are abnormal operations of rising volatage AFC 9V |
| * by RID enable/disable in the muic_sysfs_refresh_adc functions in the |
| * factory bianary. This is to minimize unnecessary interrupt by RID |
| * enable/disable whenever reading adc sysfs node |
| */ |
| MUIC_PDATA_FUNC(muic_if->get_afc_ready, muic_pdata->drv_data, &is_afc_muic_ready); |
| if (muic_pdata->is_factory_start && muic_pdata->attached_dev == 0) { |
| /* No cable detection means RID open */ |
| ret = ADC_OPEN; |
| } else { |
| #if IS_ENABLED(CONFIG_MUIC_HV) |
| if (muic_pdata->is_factory_start && is_afc_muic_ready) |
| /* No need to read adc in the middle of afc detection sequences */ |
| ret = ADC_GND; |
| else |
| #endif |
| { |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->control_rid_adc, |
| muic_pdata->drv_data, MUIC_DISABLE, &ret); |
| msleep(50); |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->control_rid_adc, |
| muic_pdata->drv_data, MUIC_ENABLE, &ret); |
| MUIC_PDATA_FUNC(muic_if->get_adc, muic_pdata->drv_data, &ret); |
| } |
| } |
| #if IS_ENABLED(CONFIG_MUIC_HV) |
| pr_info("%s: factory: %d attached_dev: %d afc ready: %d", __func__, |
| muic_pdata->is_factory_start, muic_pdata->attached_dev, |
| is_afc_muic_ready); |
| #endif |
| #endif |
| #else |
| MUIC_PDATA_FUNC(muic_if->get_adc, muic_pdata->drv_data, &ret); |
| #endif |
| |
| if (ret < 0) { |
| pr_err("%s err read adc reg(%d)\n", |
| __func__, ret); |
| return sprintf(buf, "UNKNOWN\n"); |
| } |
| |
| return sprintf(buf, "%x\n", ret); |
| } |
| |
| static ssize_t muic_sysfs_show_usb_state(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| static unsigned long swtich_slot_time; |
| |
| if (printk_timed_ratelimit(&swtich_slot_time, 5000)) |
| pr_info("%s muic_pdata->attached_dev(%d)\n", |
| __func__, muic_pdata->attached_dev); |
| |
| switch (muic_pdata->attached_dev) { |
| case ATTACHED_DEV_USB_MUIC: |
| case ATTACHED_DEV_CDP_MUIC: |
| case ATTACHED_DEV_JIG_USB_OFF_MUIC: |
| case ATTACHED_DEV_JIG_USB_ON_MUIC: |
| return sprintf(buf, "USB_STATE_CONFIGURED\n"); |
| default: |
| break; |
| } |
| |
| return 0; |
| } |
| |
| #if IS_ENABLED(CONFIG_MUIC_DEBUG) |
| static ssize_t muic_sysfs_show_mansw(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| char mesg[256] = ""; |
| int ret; |
| |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->show_register, muic_pdata->drv_data, mesg, &ret); |
| pr_info("%s:%s\n", __func__, mesg); |
| return sprintf(buf, "%s\n", mesg); |
| } |
| |
| static ssize_t muic_sysfs_show_interrupt_status(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| char mesg[256] = ""; |
| int ret; |
| |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->show_register, muic_pdata->drv_data, mesg, &ret); |
| pr_info("%s:%s\n", __func__, mesg); |
| return sprintf(buf, "%s\n", mesg); |
| } |
| |
| static ssize_t muic_sysfs_show_registers(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| char mesg[256] = ""; |
| int ret; |
| |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->show_register, muic_pdata->drv_data, mesg, &ret); |
| pr_info("%s:%s\n", __func__, mesg); |
| return sprintf(buf, "%s\n", mesg); |
| } |
| #endif |
| |
| #if IS_ENABLED(CONFIG_USB_HOST_NOTIFY) |
| static ssize_t muic_sysfs_show_otg_test(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| char mesg[256] = ""; |
| int ret; |
| |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->show_register, muic_pdata->drv_data, mesg, &ret); |
| pr_info("%s:%s\n", __func__, mesg); |
| return sprintf(buf, "%s\n", mesg); |
| } |
| |
| static ssize_t muic_sysfs_set_otg_test(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| #if IS_ENABLED(CONFIG_SEC_FACTORY) |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| int ret =0; |
| #endif |
| |
| pr_info("%s buf:%s\n", __func__, buf); |
| |
| /* |
| * The otg_test is set 0 durring the otg test. Not 1 !!! |
| */ |
| |
| if (!strncmp(buf, "0", 1)) { |
| muic_pdata->is_otg_test = 1; |
| #if IS_ENABLED(CONFIG_SEC_FACTORY) |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->set_otg_reg, muic_pdata->drv_data, 1, &ret); |
| #endif |
| } else if (!strncmp(buf, "1", 1)) { |
| muic_pdata->is_otg_test = 0; |
| #if IS_ENABLED(CONFIG_SEC_FACTORY) |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->set_otg_reg, muic_pdata->drv_data, 0, &ret); |
| #endif |
| } else { |
| pr_info("%s Wrong command\n", __func__); |
| return count; |
| } |
| |
| return count; |
| } |
| #endif |
| |
| static ssize_t muic_sysfs_show_attached_dev(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| int mdev = muic_pdata->attached_dev; |
| |
| pr_info("%s attached_dev:%d\n", __func__, mdev); |
| |
| switch (mdev) { |
| case ATTACHED_DEV_NONE_MUIC: |
| return sprintf(buf, "No VPS\n"); |
| case ATTACHED_DEV_USB_MUIC: |
| return sprintf(buf, "USB\n"); |
| case ATTACHED_DEV_CDP_MUIC: |
| return sprintf(buf, "CDP\n"); |
| case ATTACHED_DEV_OTG_MUIC: |
| return sprintf(buf, "OTG\n"); |
| case ATTACHED_DEV_TA_MUIC: |
| return sprintf(buf, "TA\n"); |
| case ATTACHED_DEV_JIG_UART_OFF_MUIC: |
| return sprintf(buf, "JIG UART OFF\n"); |
| case ATTACHED_DEV_JIG_UART_OFF_VB_MUIC: |
| return sprintf(buf, "JIG UART OFF/VB\n"); |
| case ATTACHED_DEV_JIG_UART_ON_MUIC: |
| return sprintf(buf, "JIG UART ON\n"); |
| case ATTACHED_DEV_JIG_UART_ON_VB_MUIC: |
| return sprintf(buf, "JIG UART ON/VB\n"); |
| case ATTACHED_DEV_JIG_USB_OFF_MUIC: |
| return sprintf(buf, "JIG USB OFF\n"); |
| case ATTACHED_DEV_JIG_USB_ON_MUIC: |
| return sprintf(buf, "JIG USB ON\n"); |
| case ATTACHED_DEV_DESKDOCK_MUIC: |
| case ATTACHED_DEV_DESKDOCK_VB_MUIC: |
| return sprintf(buf, "DESKDOCK\n"); |
| case ATTACHED_DEV_AUDIODOCK_MUIC: |
| return sprintf(buf, "AUDIODOCK\n"); |
| case ATTACHED_DEV_CHARGING_CABLE_MUIC: |
| return sprintf(buf, "PS CABLE\n"); |
| case ATTACHED_DEV_AFC_CHARGER_5V_MUIC: |
| case ATTACHED_DEV_AFC_CHARGER_9V_MUIC: |
| case ATTACHED_DEV_QC_CHARGER_5V_MUIC: |
| case ATTACHED_DEV_QC_CHARGER_9V_MUIC: |
| case ATTACHED_DEV_AFC_CHARGER_DISABLED_MUIC: |
| return sprintf(buf, "AFC Charger\n"); |
| case ATTACHED_DEV_FACTORY_UART_MUIC: |
| return sprintf(buf, "FACTORY UART\n"); |
| default: |
| break; |
| } |
| |
| return sprintf(buf, "UNKNOWN\n"); |
| } |
| |
| static ssize_t muic_sysfs_show_audio_path(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| return 0; |
| } |
| |
| static ssize_t muic_sysfs_set_audio_path(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| return 0; |
| } |
| |
| static ssize_t muic_sysfs_show_apo_factory(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| const char *mode; |
| |
| /* true: Factory mode, false: not Factory mode */ |
| if (muic_pdata->is_factory_start) |
| mode = "FACTORY_MODE"; |
| else |
| mode = "NOT_FACTORY_MODE"; |
| |
| pr_info("%s : %s\n", |
| __func__, mode); |
| |
| return sprintf(buf, "%s\n", mode); |
| } |
| |
| static ssize_t muic_sysfs_set_apo_factory(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| |
| /* "FACTORY_START": factory mode */ |
| if (!strncmp(buf, "FACTORY_START", 13)) |
| muic_pdata->is_factory_start = true; |
| else |
| pr_info("%s Wrong command\n", __func__); |
| |
| return count; |
| } |
| |
| static ssize_t muic_show_vbus_value(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| int val = 0; |
| |
| MUIC_PDATA_FUNC(muic_if->get_vbus_voltage, muic_pdata->drv_data, &val); |
| |
| if (val > 0) |
| return sprintf(buf, "%dV\n", val); |
| |
| #if defined(CONFIG_MUIC_S2MU205) //s2mu205 muic doesn't support vbus voltage reading, so its NA(Not Applicable) |
| return sprintf(buf, "NA\n"); |
| #else |
| return sprintf(buf, "UNKNOWN\n"); |
| #endif |
| } |
| |
| #if IS_ENABLED(CONFIG_MUIC_HV) |
| static ssize_t muic_sysfs_show_afc_disable(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| |
| if (muic_pdata->afc_disable) { |
| pr_info("%s AFC DISABLE\n", __func__); |
| return sprintf(buf, "1\n"); |
| } |
| |
| pr_info("%s AFC ENABLE", __func__); |
| return sprintf(buf, "0\n"); |
| } |
| |
| static ssize_t muic_sysfs_set_afc_disable(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = pdata->muic_if; |
| bool curr_val = pdata->afc_disable; |
| int param_val, ret = 0; |
| union power_supply_propval psy_val; |
| |
| if (!strncasecmp(buf, "1", 1)) |
| pdata->afc_disable = true; |
| else if (!strncasecmp(buf, "0", 1)) |
| pdata->afc_disable = false; |
| else |
| pr_warn("%s invalid value\n", __func__); |
| |
| #if IS_ENABLED(CONFIG_MUIC_MANAGER) |
| param_val = pdata->afc_disable ? '1' : '0'; |
| #endif |
| |
| #ifdef CM_OFFSET |
| ret = sec_set_param(CM_OFFSET + 1, (char)param_val); |
| if (ret < 0) { |
| pr_err("%s:set_param failed - %02x:%02x(%d)\n", |
| __func__, param_val, curr_val, ret); |
| pdata->afc_disable = curr_val; |
| return ret; |
| } |
| #else |
| pr_err("%s:set_param is NOT supported! - %02x:%02x(%d)\n", |
| __func__, param_val, curr_val, ret); |
| #endif |
| |
| psy_val.intval = param_val; |
| psy_do_property("battery", set, POWER_SUPPLY_EXT_PROP_HV_DISABLE, psy_val); |
| |
| pr_info("%s afc_disable(%d)\n", __func__, pdata->afc_disable); |
| if (curr_val != pdata->afc_disable) |
| MUIC_PDATA_VOID_FUNC(muic_if->set_chgtype_usrcmd, pdata->drv_data); |
| |
| return count; |
| } |
| |
| #if IS_ENABLED(CONFIG_HV_MUIC_VOLTAGE_CTRL) |
| static ssize_t muic_store_afc_set_voltage(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *muic_pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = muic_pdata->muic_if; |
| int ret = 0; |
| |
| if (!strncasecmp(buf, "5V", 2)) { |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->set_afc_voltage, muic_pdata->drv_data, 5, &ret); |
| } else if (!strncasecmp(buf, "9V", 2)) { |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->set_afc_voltage, muic_pdata->drv_data, 9, &ret); |
| } else { |
| pr_warn("%s invalid value : %s\n", __func__, buf); |
| } |
| |
| return count; |
| } |
| #endif /* CONFIG_HV_MUIC_VOLTAGE_CTRL */ |
| #endif /* CONFIG_MUIC_HV */ |
| |
| #if IS_ENABLED(CONFIG_HICCUP_CHARGER) |
| static ssize_t hiccup_show(struct device *dev, |
| struct device_attribute *attr, char *buf) |
| { |
| struct muic_platform_data *pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = pdata->muic_if; |
| int ret; |
| |
| MUIC_PDATA_FUNC(muic_if->get_hiccup_mode, |
| pdata->drv_data, &ret); |
| |
| if (ret) |
| return sprintf(buf, "ENABLE\n"); |
| else |
| return sprintf(buf, "DISABLE\n"); |
| } |
| |
| static ssize_t hiccup_store(struct device *dev, |
| struct device_attribute *attr, const char *buf, size_t count) |
| { |
| struct muic_platform_data *pdata = dev_get_drvdata(dev); |
| struct muic_interface_t *muic_if = pdata->muic_if; |
| int ret; |
| |
| if (!strncasecmp(buf, "DISABLE", 7)) { |
| MUIC_PDATA_FUNC_MULTI_PARAM(muic_if->set_hiccup_mode, |
| pdata->drv_data, MUIC_DISABLE, &ret); |
| MUIC_PDATA_FUNC(muic_if->set_com_to_open, |
| pdata->drv_data, &ret); |
| } else |
| pr_warn("%s invalid com : %s\n", __func__, buf); |
| |
| return count; |
| } |
| #endif /* CONFIG_HICCUP_CHARGER */ |
| |
| static DEVICE_ATTR(uart_en, 0664, muic_sysfs_show_uart_en, |
| muic_sysfs_set_uart_en); |
| static DEVICE_ATTR(uart_sel, 0664, muic_sysfs_show_uart_sel, |
| muic_sysfs_set_uart_sel); |
| static DEVICE_ATTR(usb_sel, 0664, muic_sysfs_show_usb_sel, |
| muic_sysfs_set_usb_sel); |
| static DEVICE_ATTR(adc, 0664, muic_sysfs_show_adc, NULL); |
| |
| #if IS_ENABLED(DEBUG_MUIC) |
| static DEVICE_ATTR(mansw, 0664, muic_sysfs_show_mansw, NULL); |
| static DEVICE_ATTR(dump_registers, 0664, muic_sysfs_show_registers, NULL); |
| static DEVICE_ATTR(int_status, 0664, muic_sysfs_show_interrupt_status, NULL); |
| #endif |
| static DEVICE_ATTR(usb_state, 0664, muic_sysfs_show_usb_state, NULL); |
| #if IS_ENABLED(CONFIG_USB_HOST_NOTIFY) |
| static DEVICE_ATTR(otg_test, 0664, |
| muic_sysfs_show_otg_test, muic_sysfs_set_otg_test); |
| #endif |
| static DEVICE_ATTR(attached_dev, 0664, muic_sysfs_show_attached_dev, NULL); |
| static DEVICE_ATTR(audio_path, 0664, |
| muic_sysfs_show_audio_path, muic_sysfs_set_audio_path); |
| static DEVICE_ATTR(apo_factory, 0664, |
| muic_sysfs_show_apo_factory, |
| muic_sysfs_set_apo_factory); |
| static DEVICE_ATTR(usb_en, 0664, |
| muic_sysfs_show_usb_en, |
| muic_sysfs_set_usb_en); |
| static DEVICE_ATTR(vbus_value, 0444, muic_show_vbus_value, NULL); |
| #if IS_ENABLED(CONFIG_MUIC_HV) |
| static DEVICE_ATTR(afc_disable, 0664, |
| muic_sysfs_show_afc_disable, muic_sysfs_set_afc_disable); |
| #if IS_ENABLED(CONFIG_HV_MUIC_VOLTAGE_CTRL) |
| static DEVICE_ATTR(afc_set_voltage, 0220, |
| NULL, muic_store_afc_set_voltage); |
| #endif /* CONFIG_HV_MUIC_VOLTAGE_CTRL */ |
| #endif /* CONFIG_MUIC_HV */ |
| #if IS_ENABLED(CONFIG_HICCUP_CHARGER) |
| static DEVICE_ATTR_RW(hiccup); |
| #endif /* CONFIG_HICCUP_CHARGER */ |
| |
| static struct attribute *muic_sysfs_attributes[] = { |
| &dev_attr_uart_en.attr, |
| &dev_attr_uart_sel.attr, |
| &dev_attr_usb_sel.attr, |
| &dev_attr_adc.attr, |
| #if IS_ENABLED(DEBUG_MUIC) |
| &dev_attr_mansw.attr, |
| &dev_attr_dump_registers.attr, |
| &dev_attr_int_status.attr, |
| #endif |
| &dev_attr_usb_state.attr, |
| #if IS_ENABLED(CONFIG_USB_HOST_NOTIFY) |
| &dev_attr_otg_test.attr, |
| #endif |
| &dev_attr_attached_dev.attr, |
| &dev_attr_audio_path.attr, |
| &dev_attr_apo_factory.attr, |
| &dev_attr_usb_en.attr, |
| &dev_attr_vbus_value.attr, |
| #if IS_ENABLED(CONFIG_MUIC_HV) |
| &dev_attr_afc_disable.attr, |
| #if IS_ENABLED(CONFIG_HV_MUIC_VOLTAGE_CTRL) |
| &dev_attr_afc_set_voltage.attr, |
| #endif /* CONFIG_HV_MUIC_VOLTAGE_CTRL */ |
| #endif /* CONFIG_MUIC_HV */ |
| #if IS_ENABLED(CONFIG_HICCUP_CHARGER) |
| &dev_attr_hiccup.attr, |
| #endif /* CONFIG_HICCUP_CHARGER */ |
| NULL |
| }; |
| |
| static const struct attribute_group muic_sysfs_group = { |
| .attrs = muic_sysfs_attributes, |
| }; |
| |
| int muic_sysfs_init(struct muic_platform_data *muic_pdata) |
| { |
| int ret; |
| /* create sysfs group */ |
| #if IS_ENABLED(CONFIG_SEC_FACTORY) |
| muic_pdata->switch_device = sec_device_find("switch"); |
| #endif |
| mutex_init(&muic_pdata->sysfs_mutex); |
| |
| if (muic_pdata->switch_device == NULL) |
| muic_pdata->switch_device = sec_device_create(NULL, "switch"); |
| |
| if (IS_ERR(muic_pdata->switch_device)) { |
| pr_err("%s Failed to create device(switch)!\n", __func__); |
| ret = -ENODEV; |
| return ret; |
| } |
| |
| ret = sysfs_create_group(&muic_pdata->switch_device->kobj, &muic_sysfs_group); |
| if (ret) { |
| pr_err("failed to create sysfs\n"); |
| return ret; |
| } |
| dev_set_drvdata(muic_pdata->switch_device, muic_pdata); |
| return ret; |
| } |
| |
| void muic_sysfs_deinit(struct muic_platform_data *muic_pdata) |
| { |
| if (muic_pdata->switch_device) |
| sysfs_remove_group(&muic_pdata->switch_device->kobj, &muic_sysfs_group); |
| } |