Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: sc27xx - add support for sc2730 and sc2721

Add new compatible strings and match data to support sc2730 and sc2721
which are two varieties of SC27XX family.

Signed-off-by: Nemo Han <nemo.han@unisoc.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Link: https://lore.kernel.org/r/20201117034949.47877-2-zhang.lyra@gmail.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Nemo Han and committed by
Dmitry Torokhov
3993a1a9 0010d7bb

+61 -14
+61 -14
drivers/input/misc/sc27xx-vibra.c
··· 3 3 * Copyright (C) 2018 Spreadtrum Communications Inc. 4 4 */ 5 5 6 - #include <linux/module.h> 7 - #include <linux/of_address.h> 8 - #include <linux/platform_device.h> 9 - #include <linux/regmap.h> 6 + #include <linux/device.h> 10 7 #include <linux/input.h> 8 + #include <linux/mod_devicetable.h> 9 + #include <linux/module.h> 10 + #include <linux/platform_device.h> 11 + #include <linux/property.h> 12 + #include <linux/regmap.h> 11 13 #include <linux/workqueue.h> 12 14 13 - #define CUR_DRV_CAL_SEL GENMASK(13, 12) 14 - #define SLP_LDOVIBR_PD_EN BIT(9) 15 - #define LDO_VIBR_PD BIT(8) 15 + #define CUR_DRV_CAL_SEL GENMASK(13, 12) 16 + #define SLP_LDOVIBR_PD_EN BIT(9) 17 + #define LDO_VIBR_PD BIT(8) 18 + #define SC2730_CUR_DRV_CAL_SEL 0 19 + #define SC2730_SLP_LDOVIBR_PD_EN BIT(14) 20 + #define SC2730_LDO_VIBR_PD BIT(13) 21 + 22 + struct sc27xx_vibra_data { 23 + u32 cur_drv_cal_sel; 24 + u32 slp_pd_en; 25 + u32 ldo_pd; 26 + }; 16 27 17 28 struct vibra_info { 18 29 struct input_dev *input_dev; 19 30 struct work_struct play_work; 20 31 struct regmap *regmap; 32 + const struct sc27xx_vibra_data *data; 21 33 u32 base; 22 34 u32 strength; 23 35 bool enabled; 24 36 }; 25 37 38 + static const struct sc27xx_vibra_data sc2731_data = { 39 + .cur_drv_cal_sel = CUR_DRV_CAL_SEL, 40 + .slp_pd_en = SLP_LDOVIBR_PD_EN, 41 + .ldo_pd = LDO_VIBR_PD, 42 + }; 43 + 44 + static const struct sc27xx_vibra_data sc2730_data = { 45 + .cur_drv_cal_sel = SC2730_CUR_DRV_CAL_SEL, 46 + .slp_pd_en = SC2730_SLP_LDOVIBR_PD_EN, 47 + .ldo_pd = SC2730_LDO_VIBR_PD, 48 + }; 49 + 50 + static const struct sc27xx_vibra_data sc2721_data = { 51 + .cur_drv_cal_sel = CUR_DRV_CAL_SEL, 52 + .slp_pd_en = SLP_LDOVIBR_PD_EN, 53 + .ldo_pd = LDO_VIBR_PD, 54 + }; 55 + 26 56 static void sc27xx_vibra_set(struct vibra_info *info, bool on) 27 57 { 58 + const struct sc27xx_vibra_data *data = info->data; 28 59 if (on) { 29 - regmap_update_bits(info->regmap, info->base, LDO_VIBR_PD, 0); 60 + regmap_update_bits(info->regmap, info->base, data->ldo_pd, 0); 30 61 regmap_update_bits(info->regmap, info->base, 31 - SLP_LDOVIBR_PD_EN, 0); 62 + data->slp_pd_en, 0); 32 63 info->enabled = true; 33 64 } else { 34 - regmap_update_bits(info->regmap, info->base, LDO_VIBR_PD, 35 - LDO_VIBR_PD); 65 + regmap_update_bits(info->regmap, info->base, data->ldo_pd, 66 + data->ldo_pd); 36 67 regmap_update_bits(info->regmap, info->base, 37 - SLP_LDOVIBR_PD_EN, SLP_LDOVIBR_PD_EN); 68 + data->slp_pd_en, data->slp_pd_en); 38 69 info->enabled = false; 39 70 } 40 71 } 41 72 42 73 static int sc27xx_vibra_hw_init(struct vibra_info *info) 43 74 { 44 - return regmap_update_bits(info->regmap, info->base, CUR_DRV_CAL_SEL, 0); 75 + const struct sc27xx_vibra_data *data = info->data; 76 + 77 + if (!data->cur_drv_cal_sel) 78 + return 0; 79 + 80 + return regmap_update_bits(info->regmap, info->base, 81 + data->cur_drv_cal_sel, 0); 45 82 } 46 83 47 84 static void sc27xx_vibra_play_work(struct work_struct *work) ··· 115 78 static int sc27xx_vibra_probe(struct platform_device *pdev) 116 79 { 117 80 struct vibra_info *info; 81 + const struct sc27xx_vibra_data *data; 118 82 int error; 83 + 84 + data = device_get_match_data(&pdev->dev); 85 + if (!data) { 86 + dev_err(&pdev->dev, "no matching driver data found\n"); 87 + return -EINVAL; 88 + } 119 89 120 90 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 121 91 if (!info) ··· 149 105 info->input_dev->name = "sc27xx:vibrator"; 150 106 info->input_dev->id.version = 0; 151 107 info->input_dev->close = sc27xx_vibra_close; 108 + info->data = data; 152 109 153 110 input_set_drvdata(info->input_dev, info); 154 111 input_set_capability(info->input_dev, EV_FF, FF_RUMBLE); ··· 179 134 } 180 135 181 136 static const struct of_device_id sc27xx_vibra_of_match[] = { 182 - { .compatible = "sprd,sc2731-vibrator", }, 137 + { .compatible = "sprd,sc2721-vibrator", .data = &sc2721_data }, 138 + { .compatible = "sprd,sc2730-vibrator", .data = &sc2730_data }, 139 + { .compatible = "sprd,sc2731-vibrator", .data = &sc2731_data }, 183 140 {} 184 141 }; 185 142 MODULE_DEVICE_TABLE(of, sc27xx_vibra_of_match);