static int i2s_gpio_set(struct snd_soc_card *card) { struct aml_audio_private_data *p_aml_audio; const char *str=NULL; int ret; p_aml_audio = snd_soc_card_get_drvdata(card); if(p_aml_audio->pin_ctl) devm_pinctrl_put(p_aml_audio->pin_ctl); ret = of_property_read_string(card->dev->of_node, "I2S_MCLK", &str); if (ret < 0) { printk("I2S_MCLK: faild to get gpio I2S_MCLK!\n"); }else{ p_aml_audio->gpio_i2s_m = amlogic_gpio_name_map_num(str); amlogic_gpio_request_one(p_aml_audio->gpio_i2s_m,GPIOF_OUT_INIT_LOW,"low_mclk"); amlogic_set_value(p_aml_audio->gpio_i2s_m, 0, "low_mclk"); } ret = of_property_read_string(card->dev->of_node, "I2S_SCLK", &str); if (ret < 0) { printk("I2S_SCLK: faild to get gpio I2S_SCLK!\n"); }else{ p_aml_audio->gpio_i2s_s = amlogic_gpio_name_map_num(str); amlogic_gpio_request_one(p_aml_audio->gpio_i2s_s,GPIOF_OUT_INIT_LOW,"low_sclk"); amlogic_set_value(p_aml_audio->gpio_i2s_s, 0, "low_sclk"); } ret = of_property_read_string(card->dev->of_node, "I2S_LRCLK", &str); if (ret < 0) { printk("I2S_LRCLK: faild to get gpio I2S_LRCLK!\n"); }else{ p_aml_audio->gpio_i2s_r = amlogic_gpio_name_map_num(str); amlogic_gpio_request_one(p_aml_audio->gpio_i2s_r,GPIOF_OUT_INIT_LOW,"low_lrclk"); amlogic_set_value(p_aml_audio->gpio_i2s_r, 0, "low_lrclk"); } ret = of_property_read_string(card->dev->of_node, "I2S_ODAT", &str); if (ret < 0) { printk("I2S_ODAT: faild to get gpio I2S_ODAT!\n"); }else{ p_aml_audio->gpio_i2s_o = amlogic_gpio_name_map_num(str); amlogic_gpio_request_one(p_aml_audio->gpio_i2s_o,GPIOF_OUT_INIT_LOW,"low_odata"); amlogic_set_value(p_aml_audio->gpio_i2s_o, 0, "low_odata"); } //mute spk amlogic_set_value(p_aml_audio->gpio_mute, 0, "mute_spk"); return 0; }
static void aml_m8_pinmux_init(struct snd_soc_card *card) { struct aml_audio_private_data *p_aml_audio; const char *str=NULL; int ret; p_aml_audio = snd_soc_card_get_drvdata(card); p_aml_audio->pin_ctl = devm_pinctrl_get_select(card->dev, "aml_snd_m8"); #if USE_EXTERNAL_DAC #ifndef CONFIG_MESON_TRUSTZONE //aml_write_reg32(P_AO_SECURE_REG1,0x00000000); aml_clr_reg32_mask(P_AO_SECURE_REG1, ((1<<8) | (1<<1))); #else /* Secure reg can only be accessed in Secure World if TrustZone enabled. */ //meson_secure_reg_write(P_AO_SECURE_REG1, 0x00000000); meson_secure_reg_write(P_AO_SECURE_REG1, meson_secure_reg_read(P_AO_SECURE_REG1) & (~((1<<8) | (1<<1)))); #endif /* CONFIG_MESON_TRUSTZONE */ #endif ret = of_property_read_string(card->dev->of_node, "mute_gpio", &str); if (ret < 0) { printk("aml_snd_m8: faild to get mute_gpio!\n"); }else{ p_aml_audio->gpio_mute = amlogic_gpio_name_map_num(str); p_aml_audio->mute_inv = of_property_read_bool(card->dev->of_node,"mute_inv"); amlogic_gpio_request_one(p_aml_audio->gpio_mute,GPIOF_OUT_INIT_HIGH,"mute_spk"); amlogic_set_value(p_aml_audio->gpio_mute, 0, "mute_spk"); spk_gpio_mute = p_aml_audio->gpio_mute; printk(KERN_INFO"pinmux set : spk_gpio_mute=%d\n",spk_gpio_mute); } printk("=%s==,aml_m8_pinmux_init done,---%d\n",__func__,p_aml_audio->det_pol_inv); }
static int __init meson_reboot_setup(void) { po_gpio = amlogic_gpio_name_map_num("GPIOAO_2"); amlogic_gpio_request_one(po_gpio, GPIOF_OUT_INIT_HIGH, "gpio_poweroff"); pm_power_off_prepare = meson_power_off_prepare; pm_power_off = meson_power_off; // pm_idle = meson_power_idle; return 0; }
static void aml_m6_pinmux_init(struct snd_soc_card *card) { struct aml_audio_private_data *p_aml_audio; const char *str; int ret; p_aml_audio = snd_soc_card_get_drvdata(card); p_aml_audio->pin_ctl = devm_pinctrl_get_select(card->dev, "wm8960_audio"); #if HP_DET //p_aml_audio->gpio_hp_det = of_get_named_gpio(card->dev->of_node,"wm8960_gpio",0); ret = of_property_read_string(card->dev->of_node, "wm8960_gpio", &str); if (ret) { printk("wm8960: faild to get gpio!\n"); } p_aml_audio->gpio_hp_det = amlogic_gpio_name_map_num(str); p_aml_audio->det_pol_inv = of_property_read_bool(card->dev->of_node,"hp_det_inv"); amlogic_gpio_request_one(p_aml_audio->gpio_hp_det,GPIOF_IN,"wm8960"); #endif printk("=%s==,aml_m6_pinmux_init done,---%d\n",__func__,p_aml_audio->det_pol_inv); }
GET_DT_ERR_TYPE get_dt_data(struct device_node* of_node, struct touch_pdata *pdata) { const char *str; int err, retry, i; int irq_table[4] = { GPIO_IRQ_HIGH, GPIO_IRQ_LOW, GPIO_IRQ_RISING, GPIO_IRQ_FALLING, }; const char *irq_string[] = { "GPIO_IRQ_HIGH", "GPIO_IRQ_LOW", "GPIO_IRQ_RISING", "GPIO_IRQ_FALLING", }; if (pdata->fw_file) strcpy(pdata->fw_file, "/system/etc/touch/touch.fw"); if (pdata->config_file) strcpy(pdata->config_file, "/system/etc/touch/touch.cfg"); if (!of_node) { printk("%s: dev.of_node == NULL!\n", pdata->owner); return ERR_NO_NODE; } err = of_property_read_string(of_node, "touch_name", (const char **)&pdata->owner); if (err) { pdata->owner = "amlogic"; printk("info: set name amlogic!\n"); } err = of_property_read_u32(of_node,"reg",&pdata->reg); if (err) { printk("%s info: get ic type!\n", pdata->owner); pdata->reg = 0; } printk("%s: reg=%x\n", pdata->owner, pdata->reg); err = of_property_read_string(of_node, "i2c_bus", &str); if (err) { printk("%s info: get i2c_bus str,use default i2c bus!\n", pdata->owner); pdata->bus_type = AML_I2C_BUS_A; } else { if (!strncmp(str, "i2c_bus_a", 9)) pdata->bus_type = AML_I2C_BUS_A; else if (!strncmp(str, "i2c_bus_b", 9)) pdata->bus_type = AML_I2C_BUS_B; else if (!strncmp(str, "i2c_bus_ao", 10)) pdata->bus_type = AML_I2C_BUS_AO; else pdata->bus_type = AML_I2C_BUS_A; } printk("%s: bus_type=%d\n", pdata->owner, pdata->bus_type); err = of_property_read_u32(of_node,"ic_type",&pdata->ic_type); if (err) { printk("%s info: get ic type!\n", pdata->owner); pdata->ic_type = 0; } printk("%s: IC type=%d\n", pdata->owner, pdata->ic_type); err = of_property_read_u32(of_node,"irq",&pdata->irq); if (err) { printk("%s: get IRQ number!\n", pdata->owner); pdata->irq = 0; } pdata->irq += INT_GPIO_0; printk("%s: IRQ number=%d\n",pdata->owner, pdata->irq); err = of_property_read_string(of_node,"irq_edge",&str); if (err) { printk("%s info: get irq edge, set irq edge GPIO_IRQ_FALLING!\n", pdata->owner); pdata->irq_edge = irq_table[3]; } else { for (retry=0; retry<4; retry++) { if (!strcmp(str, irq_string[retry])) break; } if (retry == 4) { printk("%s info: get irq edge, set irq edge GPIO_IRQ_FALLING!\n", pdata->owner); pdata->irq_edge = irq_table[3]; } else pdata->irq_edge = irq_table[retry]; } err = of_property_read_u32(of_node,"auto_update_fw",&pdata->auto_update_fw); if (err) { printk("%s info: get auto_update_fw!\n", pdata->owner); pdata->auto_update_fw = 0; } err = of_property_read_u32(of_node,"xres",&pdata->xres); if (err) { printk("%s info: get x resolution!\n", pdata->owner); return ERR_GET_DATA; } err = of_property_read_u32(of_node,"yres",&pdata->yres); if (err) { printk("%s info: get y resolution!\n",pdata->owner); return ERR_GET_DATA; } err = of_property_read_u32(of_node,"pol",&pdata->pol); if (err) { printk("%s info: get pol!\n", pdata->owner); pdata->pol = 0; } err = of_property_read_u32(of_node,"max_num",&pdata->max_num); if (err) { printk("%s info: get max num, set max num 5!\n", pdata->owner); pdata->max_num = 5; } printk("%s: xres=%d, yres=%d, pol=0x%x, max_num=%d\n",pdata->owner,pdata->xres,pdata->yres,pdata->pol,pdata->max_num); err = of_property_read_string(of_node, "gpio_interrupt", &str); if (err) { printk("%s info: get gpio interrupt!\n", pdata->owner); pdata->gpio_interrupt = 0; return ERR_GET_DATA; } else { pdata->gpio_interrupt = amlogic_gpio_name_map_num(str); printk("%s: alloc gpio_interrupt(%s)!\n", pdata->owner, str); if (pdata->gpio_interrupt <= 0) { pdata->gpio_interrupt = 0; printk("%s info: alloc gpio_interrupt(%s)!\n", pdata->owner, str); //return ERR_GPIO_REQ; } } err = of_property_read_string(of_node, "gpio_reset", &str); if (!err){ pdata->gpio_reset = amlogic_gpio_name_map_num(str); printk("%s: alloc gpio_reset(%s)!\n", pdata->owner, str); if (pdata->gpio_reset <= 0) { pdata->gpio_reset = 0; printk("%s info: alloc gpio_reset(%s)!\n", pdata->owner, str); } } else { pdata->gpio_reset = 0; } err = of_property_read_string(of_node, "gpio_power", &str); if (!err){ pdata->gpio_power = amlogic_gpio_name_map_num(str); printk("%s: alloc gpio_power(%s)!\n", pdata->owner, str); if (pdata->gpio_power <= 0) { pdata->gpio_power = 0; printk("%s info: alloc gpio_power(%s)!\n", pdata->owner, str); } } else { pdata->gpio_power = 0; } err = of_property_read_string(of_node,"fw_file",&str); if (err) { printk("%s info: get fw_file, set firmware %s!\n",pdata->owner, pdata->fw_file); } else { strcpy(pdata->fw_file, str); printk("%s get fw_file, set firmware %s!\n",pdata->owner, pdata->fw_file); } err = of_property_read_string(of_node,"config_file", &str); if (err) { printk("%s info: get config_file, set config_file %s!\n", pdata->owner, pdata->config_file); } else { strcpy(pdata->config_file, str); printk("%s get config_file, set config_file %s!\n", pdata->owner, pdata->config_file); } err = of_property_read_u32(of_node,"select_gpio_num",&pdata->select_gpio_num); if (err) { printk("%s info: get select_gpio_num!\n", pdata->owner); pdata->select_gpio_num = 0; } if (pdata->select_gpio_num > 0) { for (i=0; i<pdata->select_gpio_num; i++) { err = of_property_read_string_index(of_node, "select_fw_gpio", i, &str); if(err < 0){ printk("%s: find select_fw_gpio[%d] faild\n", pdata->owner, i); break; } else { pdata->select_fw_gpio[i] = amlogic_gpio_name_map_num(str); printk("%s: alloc select_fw_gpio[%d](%s)!\n", pdata->owner, i, str); if (pdata->select_fw_gpio[i] <= 0) { pdata->select_fw_gpio[i] = 0; printk("%s info: alloc select_fw_gpio[%d](%s)!\n", pdata->owner, i, str); //return ERR_GPIO_REQ; } } } } return ERR_NO; }
static int wifi_power_probe(struct platform_device *pdev) { int ret; const char * str; pdata = kzalloc(sizeof(struct wifi_power_platform_data), GFP_KERNEL); if(!pdata) { printk("Error: can not alloc memory ------%s\n",__func__); return -1; } pdata->usb_set_power = &usb_wifi_power; if(pdev->dev.of_node) { usb_wifi = 1; ret = of_property_read_string(pdev->dev.of_node, "valid", &str); if(ret) { printk("Error: Didn't get power valid value --- %s %d\n",__func__,__LINE__); power = 1; } else { if(!strncmp(str,"low",3)) power = 0; else power = 1; } ret = of_property_read_string(pdev->dev.of_node, "power_gpio", &str); if(ret) { printk("Error: can not get power_gpio name------%s %d\n",__func__,__LINE__); return -1; } else { pdata->power_gpio = amlogic_gpio_name_map_num(str); printk("wifi_power power_gpio is %d\n",pdata->power_gpio); //ret = amlogic_gpio_request(pdata->power_gpio,WIFI_POWER_MODULE_NAME); //mcli pdata->usb_set_power(0); //power on //pdata->usb_set_power(1); //power on } if(!(ret = of_property_read_string(pdev->dev.of_node, "power_gpio2", &str))) wifi_power_on_pin2 = 1; else{ printk("wifi_dev_probe : there is no wifi_power_on_pin2 setup in DTS file!\n"); } if(wifi_power_on_pin2){ if(ret) { printk("Error: can not get power_gpio2 name------%s %d\n",__func__,__LINE__); return -1; }else{ pdata->power_gpio2 = amlogic_gpio_name_map_num(str); printk("wifi_power power_gpio2 is %d\n",pdata->power_gpio2); } } } pdev->dev.platform_data = pdata; ret = alloc_chrdev_region(&wifi_power_devno, 0, 1, WIFI_POWER_DRIVER_NAME); if (ret < 0) { printk(KERN_ERR "%s:%s failed to allocate major number\n",WIFI_POWER_MODULE_NAME,__FUNCTION__); ret = -ENODEV; goto out; } ret = class_register(&wifi_power_class); if (ret < 0) { printk(KERN_ERR "%s:%s failed to register class\n",WIFI_POWER_MODULE_NAME,__FUNCTION__); goto error1; } wifi_power_cdev = cdev_alloc(); if(!wifi_power_cdev){ printk(KERN_ERR "%s:%s failed to allocate memory\n",WIFI_POWER_MODULE_NAME,__FUNCTION__); goto error2; } cdev_init(wifi_power_cdev,&wifi_power_fops); wifi_power_cdev->owner = THIS_MODULE; ret = cdev_add(wifi_power_cdev,wifi_power_devno,1); if(ret){ printk(KERN_ERR "%s:%s failed to add device\n",WIFI_POWER_MODULE_NAME,__FUNCTION__); goto error3; } devp = device_create(&wifi_power_class,NULL,wifi_power_devno,NULL,WIFI_POWER_DEVICE_NAME); if(IS_ERR(devp)){ printk(KERN_ERR "%s:%s failed to create device node\n",WIFI_POWER_MODULE_NAME,__FUNCTION__); ret = PTR_ERR(devp); goto error3; } devp->platform_data = pdata; return 0; error3: cdev_del(wifi_power_cdev); error2: class_unregister(&wifi_power_class); error1: unregister_chrdev_region(wifi_power_devno,1); out: return ret; }
int get_lcd_extern_dt_data(struct device_node* of_node, struct lcd_extern_config_t *pdata) { int err; int val; const char *str; err = of_property_read_string(of_node, "dev_name", &str); if (err) { str = "aml_lcd_extern"; printk("warning: get dev_name failed\n"); } pdata->name = (char *)kmalloc(sizeof(char)*BL_EXT_NAME_LEN_MAX, GFP_KERNEL); if (pdata->name == NULL) { printk("[get_lcd_extern_dt_data]: Not enough memory\n"); } else { memset(pdata->name, 0, BL_EXT_NAME_LEN_MAX); strcpy(pdata->name, str); printk("load bl_extern in dtb: %s\n", pdata->name); } err = of_property_read_u32(of_node, "type", &pdata->type); if (err) { pdata->type = LCD_EXTERN_MAX; printk("warning: get type failed, exit\n"); return -1; } switch (pdata->type) { case LCD_EXTERN_I2C: err = of_property_read_u32(of_node,"i2c_address",&pdata->i2c_addr); if (err) { printk("%s warning: get i2c_address failed\n", pdata->name); pdata->i2c_addr = 0; } DBG_PRINT("%s: i2c_address=0x%02x\n", pdata->name, pdata->i2c_addr); err = of_property_read_string(of_node, "i2c_bus", &str); if (err) { printk("%s warning: get i2c_bus failed, use default i2c bus\n", pdata->name); pdata->i2c_bus = AML_I2C_MASTER_A; } else { if (strncmp(str, "i2c_bus_a", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_A; else if (strncmp(str, "i2c_bus_b", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_B; else if (strncmp(str, "i2c_bus_c", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_C; else if (strncmp(str, "i2c_bus_d", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_D; else if (strncmp(str, "i2c_bus_ao", 10) == 0) pdata->i2c_bus = AML_I2C_MASTER_AO; else pdata->i2c_bus = AML_I2C_MASTER_A; } DBG_PRINT("%s: i2c_bus=%s[%d]\n", pdata->name, str, pdata->i2c_bus); break; case LCD_EXTERN_SPI: err = of_property_read_string(of_node,"gpio_spi_cs", &str); if (err) { printk("%s warning: get spi gpio_spi_cs failed\n", pdata->name); pdata->spi_cs = -1; } else { val = amlogic_gpio_name_map_num(str); if (val > 0) { err = lcd_extern_gpio_request(val); if (err) { printk("faild to alloc spi_cs gpio (%s)!\n", str); } pdata->spi_cs = val; DBG_PRINT("spi_cs gpio = %s(%d)\n", str, pdata->spi_cs); } else { pdata->spi_cs = -1; } } err = of_property_read_string(of_node,"gpio_spi_clk", &str); if (err) { printk("%s warning: get spi gpio_spi_clk failed\n", pdata->name); pdata->spi_clk = -1; } else { val = amlogic_gpio_name_map_num(str); if (val > 0) { err = lcd_extern_gpio_request(val); if (err) { printk("faild to alloc spi_clk gpio (%s)!\n", str); } pdata->spi_clk = val; DBG_PRINT("spi_clk gpio = %s(%d)\n", str, pdata->spi_clk); } else { pdata->spi_clk = -1; } } err = of_property_read_string(of_node,"gpio_spi_data", &str); if (err) { printk("%s warning: get spi gpio_spi_data failed\n", pdata->name); pdata->spi_data = -1; } else { val = amlogic_gpio_name_map_num(str); if (val > 0) { err = lcd_extern_gpio_request(val); if (err) { printk("faild to alloc spi_data gpio (%s)!\n", str); } pdata->spi_data = val; DBG_PRINT("spi_data gpio = %s(%d)\n", str, pdata->spi_data); } else { pdata->spi_data = -1; } } break; case LCD_EXTERN_MIPI: break; default: break; } return 0; }
static int bt_probe(struct platform_device *pdev) { int ret = 0; struct rfkill *bt_rfk; struct bt_dev_data *pdata = NULL; struct bt_dev_runtime_data *prdata; #ifdef CONFIG_OF //plat = aml_get_driver_data(pdev); if (pdev->dev.of_node) { const char *str; printk(KERN_DEBUG "enter bt_probe of_node\n"); pdata = kzalloc(sizeof(struct bt_dev_data), GFP_KERNEL); ret = of_property_read_string(pdev->dev.of_node,"gpio_reset",&str); if(ret){ printk(KERN_WARNING "not get gpio_reset\n"); pdata->gpio_reset = 0; } else { pdata->gpio_reset = amlogic_gpio_name_map_num(str); } ret = of_property_read_string(pdev->dev.of_node,"gpio_en",&str); if(ret){ printk(KERN_WARNING "not get gpio_en\n"); pdata->gpio_en = 0; } else { pdata->gpio_en = amlogic_gpio_name_map_num(str); } ret = of_property_read_string(pdev->dev.of_node,"gpio_wake",&str); if(ret){ printk(KERN_WARNING "not get gpio_wake\n"); pdata->gpio_wake = 0; } else { pdata->gpio_wake = amlogic_gpio_name_map_num(str); } } #else pdata = (struct bt_dev_data *)(pdev->dev.platform_data); #endif bt_device_init(pdata); /* default to bluetooth off */ //rfkill_switch_all(RFKILL_TYPE_BLUETOOTH, 1); bt_device_off(pdata); bt_rfk = rfkill_alloc("bt-dev", &pdev->dev, RFKILL_TYPE_BLUETOOTH, &bt_rfkill_ops, pdata); if (!bt_rfk) { printk("rfk alloc fail\n"); ret = -ENOMEM; goto err_rfk_alloc; } /* if not set false, the bt_set_block will call when rfkill class resume */ rfkill_init_sw_state(bt_rfk, false); //we want to reset bt when system resume ret = rfkill_register(bt_rfk); if (ret){ printk(KERN_ERR "rfkill_register fail\n"); goto err_rfkill; } prdata = kmalloc(sizeof(struct bt_dev_runtime_data), GFP_KERNEL); if (!prdata) { printk(KERN_ERR "bt_dev_runtime_data alloc fail\n"); goto err_rfkill; } #ifdef CONFIG_AM_WIFI_SD_MMC //setup 32k clock wifi_request_32k_clk(1, BT_RFKILL); msleep(100); #endif prdata->bt_rfk = bt_rfk; prdata->pdata = pdata; platform_set_drvdata(pdev, prdata); #ifdef CONFIG_HAS_EARLYSUSPEND bt_early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB; bt_early_suspend.suspend = bt_earlysuspend; bt_early_suspend.resume = bt_lateresume; bt_early_suspend.param = pdev; register_early_suspend(&bt_early_suspend); #endif bt_device_on(pdata); return 0; err_rfkill: rfkill_destroy(bt_rfk); err_rfk_alloc: bt_device_deinit(pdata); return ret; }
int get_bl_extern_dt_data(struct device_node* of_node, struct bl_extern_config_t *pdata) { int ret; int val; unsigned int bl_para[2]; const char *str; ret = of_property_read_string(of_node, "dev_name", (const char **)&pdata->name); if (ret) { pdata->name = "aml_bl_extern"; printk("warning: get dev_name failed\n"); } ret = of_property_read_u32(of_node, "type", &pdata->type); if (ret) { pdata->type = BL_EXTERN_MAX; printk("%s warning: get type failed, exit\n", pdata->name); return -1; } pdata->gpio_used = 0; pdata->gpio = GPIO_MAX; ret = of_property_read_string_index(of_node, "gpio_enable_on_off", 0, &str); if (ret) { printk("%s warning: get gpio_enable failed\n", pdata->name); } else { if (strncmp(str, "G", 1) == 0) {//"GPIO_xx" pdata->gpio_used = 1; val = amlogic_gpio_name_map_num(str); ret = bl_extern_gpio_request(val); if (ret) { printk("%s warning: faild to alloc gpio (%s)\n", pdata->name, str); } pdata->gpio = val; } DBG_PRINT("%s: gpio_enable %s\n", pdata->name, ((pdata->gpio_used) ? str:"none")); } ret = of_property_read_string_index(of_node, "gpio_enable_on_off", 1, &str); if (ret) { printk("%s warning: get gpio_enable_on failed\n", pdata->name); } else { if (strncmp(str, "2", 1) == 0) pdata->gpio_on = LCD_POWER_GPIO_INPUT; else if (strncmp(str, "0", 1) == 0) pdata->gpio_on = LCD_POWER_GPIO_OUTPUT_LOW; else pdata->gpio_on = LCD_POWER_GPIO_OUTPUT_HIGH; } ret = of_property_read_string_index(of_node, "gpio_enable_on_off", 2, &str); if (ret) { printk("%s warning: get gpio_enable_off failed\n", pdata->name); } else { if (strncmp(str, "2", 1) == 0) pdata->gpio_off = LCD_POWER_GPIO_INPUT; else if (strncmp(str, "1", 1) == 0) pdata->gpio_off = LCD_POWER_GPIO_OUTPUT_HIGH; else pdata->gpio_off = LCD_POWER_GPIO_OUTPUT_LOW; } DBG_PRINT("%s: gpio_on = %d, gpio_off = %d \n", pdata->name, pdata->gpio_on, pdata->gpio_off); switch (pdata->type) { case BL_EXTERN_I2C: ret = of_property_read_u32(of_node,"i2c_address",&pdata->i2c_addr); if (ret) { printk("%s warning: get i2c_address failed\n", pdata->name); pdata->i2c_addr = 0; } DBG_PRINT("%s: i2c_address=0x%02x\n", pdata->name, pdata->i2c_addr); ret = of_property_read_string(of_node, "i2c_bus", &str); if (ret) { printk("%s warning: get i2c_bus failed, use default i2c bus\n", pdata->name); pdata->i2c_bus = AML_I2C_MASTER_A; } else { if (strncmp(str, "i2c_bus_a", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_A; else if (strncmp(str, "i2c_bus_b", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_B; else if (strncmp(str, "i2c_bus_c", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_C; else if (strncmp(str, "i2c_bus_d", 9) == 0) pdata->i2c_bus = AML_I2C_MASTER_D; else if (strncmp(str, "i2c_bus_ao", 10) == 0) pdata->i2c_bus = AML_I2C_MASTER_AO; else pdata->i2c_bus = AML_I2C_MASTER_A; } DBG_PRINT("%s: i2c_bus=%s[%d]\n", pdata->name, str, pdata->i2c_bus); break; case BL_EXTERN_SPI: ret = of_property_read_string(of_node,"gpio_spi_cs", &str); if (ret) { printk("%s warning: get spi gpio_spi_cs failed\n", pdata->name); pdata->spi_cs = -1; } else { val = amlogic_gpio_name_map_num(str); if (val > 0) { ret = bl_extern_gpio_request(val); if (ret) { printk("faild to alloc spi_cs gpio (%s)!\n", str); } pdata->spi_cs = val; DBG_PRINT("spi_cs gpio = %s(%d)\n", str, pdata->spi_cs); } else { pdata->spi_cs = -1; } } ret = of_property_read_string(of_node,"gpio_spi_clk", &str); if (ret) { printk("%s warning: get spi gpio_spi_clk failed\n", pdata->name); pdata->spi_clk = -1; } else { val = amlogic_gpio_name_map_num(str); if (val > 0) { ret = bl_extern_gpio_request(val); if (ret) { printk("%s: faild to alloc spi_clk gpio (%s)!\n", pdata->name, str); } pdata->spi_clk = val; DBG_PRINT("%s: spi_clk gpio = %s(%d)\n", pdata->name, str, pdata->spi_clk); } else { pdata->spi_clk = -1; } } ret = of_property_read_string(of_node,"gpio_spi_data", &str); if (ret) { printk("%s warning: get spi gpio_spi_data failed\n", pdata->name); pdata->spi_data = -1; } else { val = amlogic_gpio_name_map_num(str); if (val > 0) { ret = bl_extern_gpio_request(val); if (ret) { printk("%s: faild to alloc spi_data gpio (%s)!\n", pdata->name, str); } pdata->spi_data = val; DBG_PRINT("%s: spi_data gpio = %s(%d)\n", pdata->name, str, pdata->spi_data); } else { pdata->spi_data = -1; } } break; case BL_EXTERN_OTHER: break; default: break; } ret = of_property_read_u32_array(of_node,"dim_max_min", &bl_para[0], 2); if(ret){ printk("%s warning: get dim_max_min failed\n", pdata->name); pdata->dim_max = 0; pdata->dim_min = 0; } else { pdata->dim_max = bl_para[0]; pdata->dim_min = bl_para[1]; } DBG_PRINT("%s dim_min = %d, dim_max = %d\n", pdata->name, pdata->dim_min, pdata->dim_max); return 0; }
static int amlogic_pinctrl_parse_group(struct platform_device *pdev, struct device_node *np, int idx, const char **out_name) { struct amlogic_pmx *d = platform_get_drvdata(pdev); struct amlogic_pin_group *g = d->soc->groups; struct property *prop; const char *propname = "amlogic,pins"; const char *pinctrl_set = "amlogic,setmask"; const char *pinctrl_clr = "amlogic,clrmask"; const char *gpioname; int length,ret=0,i; u32 val; g=g+idx; g->name = np->name; #if 0 /*read amlogic pins through num*/ prop = of_find_property(np, propname, &length); if (!prop) return -EINVAL; g->num_pins = length / sizeof(u32); g->pins = devm_kzalloc(&pdev->dev, g->num_pins * sizeof(*g->pins), GFP_KERNEL); if (!g->pins) return -ENOMEM; ret=of_property_read_u32_array(np, propname, g->pins, g->num_pins); if (ret) return -EINVAL; #endif /*read amlogic pins through name*/ g->num_pins=of_property_count_strings(np, propname); if(g->num_pins>0){ g->pins = devm_kzalloc(&pdev->dev, g->num_pins * sizeof(*g->pins), GFP_KERNEL); if (!g->pins){ ret= -ENOMEM; dev_err(&pdev->dev, "malloc g->pins error\n"); goto err; } for(i=0;i<g->num_pins;i++) { ret = of_property_read_string_index(np, propname, i, &gpioname); if(ret<0){ ret= -EINVAL; dev_err(&pdev->dev, "read %s error\n",propname); goto err; } ret=amlogic_gpio_name_map_num(gpioname); if(ret<0){ ret= -EINVAL; dev_err(&pdev->dev, "%s change name to num error\n",gpioname); goto err; } g->pins[i]=ret; } } /*read amlogic set mask*/ if(!of_property_read_u32(np, pinctrl_set, &val)){ prop = of_find_property(np, pinctrl_set, &length); if (!prop){ ret= -EINVAL; dev_err(&pdev->dev, "read %s length error\n",pinctrl_set); goto err; } g->num_setmask=length / sizeof(u32); if(g->num_setmask%d->pinmux_cell){ dev_err(&pdev->dev, "num_setmask error must be multiples of 2\n"); g->num_setmask=(g->num_setmask/d->pinmux_cell)*d->pinmux_cell; } g->num_setmask=g->num_setmask/d->pinmux_cell; g->setmask= devm_kzalloc(&pdev->dev, g->num_setmask * sizeof(*g->setmask), GFP_KERNEL); if (!g->setmask){ ret= -ENOMEM; dev_err(&pdev->dev, "malloc g->setmask error\n"); goto err; } ret=of_property_read_u32_array(np, pinctrl_set, (u32 *)(g->setmask), length / sizeof(u32)); if (ret){ ret= -EINVAL; dev_err(&pdev->dev, "read %s data error\n",pinctrl_set); goto err; } }else{ g->setmask=NULL; g->num_setmask=0; } /*read clear mask*/ if(!of_property_read_u32(np, pinctrl_clr, &val)){ prop = of_find_property(np, pinctrl_clr, &length); if (!prop){ dev_err(&pdev->dev, "read %s length error\n",pinctrl_clr); ret =-EINVAL; goto err; } g->num_clearmask=length / sizeof(u32); if(g->num_clearmask%d->pinmux_cell){ dev_err(&pdev->dev, "num_setmask error must be multiples of 2\n"); g->num_clearmask=(g->num_clearmask/d->pinmux_cell)*d->pinmux_cell; } g->num_clearmask=g->num_clearmask/d->pinmux_cell; g->clearmask= devm_kzalloc(&pdev->dev, g->num_clearmask * sizeof(*g->clearmask), GFP_KERNEL); if (!g->clearmask){ ret=-ENOMEM; dev_err(&pdev->dev, "malloc g->clearmask error\n"); goto err; } ret=of_property_read_u32_array(np, pinctrl_clr,(u32 *)( g->clearmask), length / sizeof(u32)); if (ret){ ret= -EINVAL; dev_err(&pdev->dev, "read %s data error\n",pinctrl_clr); goto err; } } else{ g->clearmask=NULL; g->num_clearmask=0; } if (out_name) *out_name = g->name; return 0; err: if(g->pins) devm_kfree(&pdev->dev,g->pins); if(g->setmask) devm_kfree(&pdev->dev,g->setmask); if(g->clearmask) devm_kfree(&pdev->dev,g->clearmask); return ret; }
/** * of_get_named_gpiod_flags() - Get a GPIO descriptor and flags for GPIO API * @np: device node to get GPIO from * @propname: property name containing gpio specifier(s) * @index: index of the GPIO * @flags: a flags pointer to fill in * * Returns GPIO descriptor to use with Linux GPIO API, or one of the errno * value on the error condition. If @flags is not NULL the function also fills * in flags for the GPIO. */ struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np, const char *propname, int index, enum of_gpio_flags *flags) { /* Return -EPROBE_DEFER to support probe() functions to be called * later when the GPIO actually becomes available */ struct gg_data gg_data = { .flags = flags, .out_gpio = ERR_PTR(-EPROBE_DEFER) }; int ret; /* .of_xlate might decide to not fill in the flags, so clear it. */ if (flags) *flags = 0; ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index, &gg_data.gpiospec); if (ret) { pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n", __func__, propname, np->full_name, index); return ERR_PTR(ret); } gpiochip_find(&gg_data, of_gpiochip_find_and_xlate); of_node_put(gg_data.gpiospec.np); pr_debug("%s: parsed '%s' property of node '%s[%d]' - status (%d)\n", __func__, propname, np->full_name, index, PTR_ERR_OR_ZERO(gg_data.out_gpio)); return gg_data.out_gpio; } #if defined(CONFIG_ARCH_MESON8B) #include <linux/amlogic/aml_gpio_consumer.h> int of_get_named_gpio_flags(struct device_node *np, const char *propname, int index __attribute__((unused)), enum of_gpio_flags *flags __attribute__((unused))) { const char *str; if(of_property_read_string(np, "gpios", &str)) return -EPROBE_DEFER; return amlogic_gpio_name_map_num(str); } #else int of_get_named_gpio_flags(struct device_node *np, const char *list_name, int index, enum of_gpio_flags *flags) { struct gpio_desc *desc; desc = of_get_named_gpiod_flags(np, list_name, index, flags); if (IS_ERR(desc)) return PTR_ERR(desc); else return desc_to_gpio(desc); } #endif EXPORT_SYMBOL(of_get_named_gpio_flags); /** * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags * @gc: pointer to the gpio_chip structure * @np: device node of the GPIO chip * @gpio_spec: gpio specifier as found in the device tree * @flags: a flags pointer to fill in * * This is simple translation function, suitable for the most 1:1 mapped * gpio chips. This function performs only one sanity check: whether gpio * is less than ngpios (that is specified in the gpio_chip). */ int of_gpio_simple_xlate(struct gpio_chip *gc, const struct of_phandle_args *gpiospec, u32 *flags) { /* * We're discouraging gpio_cells < 2, since that way you'll have to * write your own xlate function (that will have to retrive the GPIO * number and the flags from a single gpio cell -- this is possible, * but not recommended). */ if (gc->of_gpio_n_cells < 2) { WARN_ON(1); return -EINVAL; } if (WARN_ON(gpiospec->args_count < gc->of_gpio_n_cells)) return -EINVAL; if (gpiospec->args[0] >= gc->ngpio) return -EINVAL; if (flags) *flags = gpiospec->args[1]; return gpiospec->args[0]; } EXPORT_SYMBOL(of_gpio_simple_xlate); /** * of_mm_gpiochip_add - Add memory mapped GPIO chip (bank) * @np: device node of the GPIO chip * @mm_gc: pointer to the of_mm_gpio_chip allocated structure * * To use this function you should allocate and fill mm_gc with: * * 1) In the gpio_chip structure: * - all the callbacks * - of_gpio_n_cells * - of_xlate callback (optional) * * 3) In the of_mm_gpio_chip structure: * - save_regs callback (optional) * * If succeeded, this function will map bank's memory and will * do all necessary work for you. Then you'll able to use .regs * to manage GPIOs from the callbacks. */ int of_mm_gpiochip_add(struct device_node *np, struct of_mm_gpio_chip *mm_gc) { int ret = -ENOMEM; struct gpio_chip *gc = &mm_gc->gc; gc->label = kstrdup(np->full_name, GFP_KERNEL); if (!gc->label) goto err0; mm_gc->regs = of_iomap(np, 0); if (!mm_gc->regs) goto err1; gc->base = -1; if (mm_gc->save_regs) mm_gc->save_regs(mm_gc); mm_gc->gc.of_node = np; ret = gpiochip_add(gc); if (ret) goto err2; return 0; err2: iounmap(mm_gc->regs); err1: kfree(gc->label); err0: pr_err("%s: GPIO chip registration failed with status %d\n", np->full_name, ret); return ret; }
int meson_cvbs_init(struct drm_device *dev) { struct device *d = dev->dev; const char *str; int ret; ret = of_property_read_string(d->of_node, "cvbs_pal_gpio", &str); if (ret < 0) { dev_warn(d, "Failed to read property \"cvbs_pal_gpio\"\n"); goto out; } gpio_pal = amlogic_gpio_name_map_num(str); if (gpio_pal < 0) { dev_warn(d, "Failed to map cvbs_pal_gpio to a GPIO number\n"); goto out; } ret = amlogic_gpio_request_one(gpio_pal, GPIOF_IN, "mesondrm pal"); if (ret < 0) { dev_warn(d, "Failed to request cvbs_pal_gpio\n"); goto out; } ret = amlogic_set_pull_up_down(gpio_pal, 1, "mesondrm pal"); if (ret < 0) { dev_warn(d, "Failed to up-down cvbs_pal_gpio\n"); goto out; } ret = of_property_read_string(d->of_node, "cvbs_ntsc_gpio", &str); if (ret < 0) { dev_warn(d, "Failed to read property \"cvbs_ntsc_gpio\"\n"); goto out; } gpio_ntsc = amlogic_gpio_name_map_num(str); if (gpio_pal < 0) { dev_warn(d, "Failed to map cvbs_ntsc_gpio to a GPIO number\n"); goto out; } ret = amlogic_gpio_request_one(gpio_ntsc, GPIOF_IN, "mesondrm ntsc"); if (ret < 0) { dev_warn(d, "Failed to request cvbs_ntsc_gpio\n"); goto out; } ret = amlogic_set_pull_up_down(gpio_ntsc, 1, "mesondrm ntsc"); if (ret < 0) { dev_warn(d, "Failed to up-down cvbs_ntsc_gpio\n"); goto out; } ret = amlogic_gpio_to_irq(gpio_pal, "mesondrm pal", AML_GPIO_IRQ(2, FILTER_NUM7, GPIO_IRQ_RISING)); if (ret < 0) { dev_warn(d, "Failed to get IRQ line for cvbs_pal_gpio rising\n"); goto out; } ret = amlogic_gpio_to_irq(gpio_pal, "mesondrm pal", AML_GPIO_IRQ(1, FILTER_NUM7, GPIO_IRQ_FALLING)); if (ret < 0) { dev_warn(d, "Failed to get IRQ line for cvbs_pal_gpio falling\n"); goto out; } meson_cvbs_work.dev = dev; INIT_DELAYED_WORK(&meson_cvbs_work.work, cvbs_switch_work_func); ret = devm_request_threaded_irq(d, INT_GPIO_2, NULL, cvbs_switch_intr_handler, IRQF_ONESHOT, "mesondrm pal", &meson_cvbs_work); if (ret < 0) { dev_warn(d, "Failed to claim cvbs_pal_gpio rising IRQ\n"); goto out; } ret = devm_request_threaded_irq(d, INT_GPIO_1, NULL, cvbs_switch_intr_handler, IRQF_ONESHOT, "mesondrm pal", &meson_cvbs_work); if (ret < 0) { dev_warn(d, "Failed to claim cvbs_pal_gpio falling IRQ\n"); goto out; } out: return ret; }