extcon: sm5502: Add support for SM5504
Subsystems (2)
cover extcon: sm5502: Add support for SM5504
This patch series adds support for SM5504 to the existing extcon-sm5502 driver. SM5502 and SM5504 are fairly similar so support for SM5504 can be added with a few simple if statements in the code.
I also put a few cleanup patches in front and convert the device tree bindings to DT schema.
I tested this patch series on both SM5502 (Samsung Galaxy A5 2015) and SM5504 (Samsung Galaxy S4 Mini Value Edition) and it seems to work just fine for both.
Stephan Gerhold (6):
extcon: sm5502: Use devm_regmap_add_irq_chip()
extcon: sm5502: Implement i2c_driver->probe_new()
extcon: sm5502: Drop invalid register write in sm5502_reg_data
dt-bindings: extcon: sm5502: Convert to DT schema
dt-bindings: extcon: sm5502: Document siliconmitus,sm5504-muic
extcon: sm5502: Add support for SM5504
.../bindings/extcon/extcon-sm5502.txt | 21 -- .../extcon/siliconmitus,sm5502-muic.yaml | 52 +++++ drivers/extcon/Kconfig | 2 +- drivers/extcon/extcon-sm5502.c | 180 +++++++++++++++--- drivers/extcon/extcon-sm5502.h | 79 ++++++++ 5 files changed, 282 insertions(+), 52 deletions(-) delete mode 100644 Documentation/devicetree/bindings/extcon/extcon-sm5502.txt create mode 100644 Documentation/devicetree/bindings/extcon/siliconmitus,sm5502-muic.yaml
Signature · 1 line
2.31.1
PATCH 1/6 extcon: sm5502: Use devm_regmap_add_irq_chip()
Use devm_regmap_add_irq_chip() to avoid having to remove the irqchip explicitly in sm5502_muic_i2c_remove().
--- drivers/extcon/extcon-sm5502.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/extcon/extcon-sm5502.c +2 -12
@@ -600,8 +600,8 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c,/* Support irq domain for SM5502 MUIC device */ irq_flags =IRQF_TRIGGER_FALLING |IRQF_ONESHOT |IRQF_SHARED ; - ret =regmap_add_irq_chip (info->regmap, info->irq, irq_flags,0 , - &sm5502_muic_irq_chip, &info->irq_data); + ret =devm_regmap_add_irq_chip (info->dev, info->regmap, info->irq, irq_flags, +0 , &sm5502_muic_irq_chip, &info->irq_data);if (ret !=0 ) {dev_err (info->dev,"failed to request IRQ %d: %d\n" , info->irq, ret);
@@ -661,15 +661,6 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c,return 0 ; } -static int sm5502_muic_i2c_remove (struct i2c_client *i2c) -{ -struct sm5502_muic_info *info =i2c_get_clientdata (i2c); - -regmap_del_irq_chip (info->irq, info->irq_data); - -return 0 ; -} -static const struct of_device_id sm5502_dt_match[] = { { .compatible ="siliconmitus,sm5502-muic" }, { },
@@ -714,7 +705,6 @@ static struct i2c_driver sm5502_muic_i2c_driver = { .of_match_table = sm5502_dt_match, }, .probe = sm5022_muic_i2c_probe, - .remove = sm5502_muic_i2c_remove, .id_table = sm5502_i2c_id, };
Signature · 1 line
2.31.1
PATCH 2/6 extcon: sm5502: Implement i2c_driver->probe_new()
In reply to Stephan Gerholdsm5022_muic_i2c_probe() does not use the i2c_device_id, so implement i2c_driver->probe_new() instead of probe().
--- drivers/extcon/extcon-sm5502.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/extcon/extcon-sm5502.c +2 -3
@@ -563,8 +563,7 @@ static void sm5502_init_dev_type(struct sm5502_muic_info *info) } } -static int sm5022_muic_i2c_probe (struct i2c_client *i2c, -const struct i2c_device_id *id) +static int sm5022_muic_i2c_probe (struct i2c_client *i2c) {struct device_node *np = i2c->dev.of_node;struct sm5502_muic_info *info;
@@ -704,7 +703,7 @@ static struct i2c_driver sm5502_muic_i2c_driver = { .pm = &sm5502_muic_pm_ops, .of_match_table = sm5502_dt_match, }, - .probe = sm5022_muic_i2c_probe, + .probe_new = sm5022_muic_i2c_probe, .id_table = sm5502_i2c_id, };
Signature · 1 line
2.31.1
PATCH 3/6 extcon: sm5502: Drop invalid register write in sm5502_reg_data
In reply to Stephan GerholdWhen sm5502_init_dev_type() iterates over sm5502_reg_data to initialize the registers it is limited by ARRAY_SIZE(sm5502_reg_data). There is no need to add another empty element to sm5502_reg_data.
Having the additional empty element in sm5502_reg_data will just result in writing 0xff to register 0x00, which does not really make sense.
--- drivers/extcon/extcon-sm5502.c | 1 - 1 file changed, 1 deletion(-)
drivers/extcon/extcon-sm5502.c +0 -1
@@ -88,7 +88,6 @@ static struct reg_data sm5502_reg_data[] = { | SM5502_REG_INTM2_MHL_MASK, .invert = true, }, - { } };/* List of detectable cables */
Signature · 1 line
2.31.1
PATCH 4/6 dt-bindings: extcon: sm5502: Convert to DT schema
In reply to Stephan GerholdConvert the extcon-sm5502 device tree bindings to DT schema.
--- .../bindings/extcon/extcon-sm5502.txt | 21 -------- .../extcon/siliconmitus,sm5502-muic.yaml | 50 +++++++++++++++++++ 2 files changed, 50 insertions(+), 21 deletions(-) delete mode 100644 Documentation/devicetree/bindings/extcon/extcon-sm5502.txt create mode 100644 Documentation/devicetree/bindings/extcon/siliconmitus,sm5502-muic.yaml
Documentation/devicetree/bindings/extcon/extcon-sm5502.txt deleted +0 -21
@@ -1,21 +0,0 @@ - -* SM5502 MUIC (Micro-USB Interface Controller) device - -The Silicon Mitus SM5502 is a MUIC (Micro-USB Interface Controller) device -which can detect the state of external accessory when external accessory is -attached or detached and button is pressed or released. It is interfaced to -the host controller using an I2C interface. - -Required properties: -- compatible: Should be "siliconmitus,sm5502-muic" -- reg: Specifies the I2C slave address of the MUIC block. It should be 0x25 -- interrupts: Interrupt specifiers for detection interrupt sources. - -Example: - - sm5502@25 { - compatible = "siliconmitus,sm5502-muic"; - interrupt-parent = <&gpx1>; - interrupts = <5 0>; - reg = <0x25>; - };
Documentation/devicetree/bindings/extcon/siliconmitus,sm5502-muic.yaml new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 5/6 dt-bindings: extcon: sm5502: Document siliconmitus,sm5504-muic
In reply to Stephan GerholdDocument support for SM5504 with the new siliconmitus,sm5504-muic compatible.
--- .../bindings/extcon/siliconmitus,sm5502-muic.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/extcon/siliconmitus,sm5502-muic.yaml +4 -2
@@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/extcon/siliconmitus,sm5502-muic.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: SM5502 MUIC (Micro-USB Interface Controller) device +title: SM5502/SM5504 MUIC (Micro-USB Interface Controller) device maintainers: - Chanwoo Choi <[email protected]>
@@ -19,10 +19,12 @@ properties: compatible: enum: - siliconmitus,sm5502-muic + - siliconmitus,sm5504-muic reg: maxItems: 1 - description: I2C slave address of the device. Usually 0x25 for SM5502. + description: I2C slave address of the device. Usually 0x25 for SM5502, + 0x14 for SM5504. interrupts: maxItems: 1
Signature · 1 line
2.31.1
PATCH 6/6 extcon: sm5502: Add support for SM5504
In reply to Stephan GerholdSM5504 is another MUIC from Silicon Mitus that is fairly similar to SM5502. They seem to use the same register set, but:
- SM5504 has some additional bits in SM5502_REG_CONTROL
- SM5504 has a quite different set of interrupts
- SM5504 reports USB OTG as dev_type1 = BIT(0) instead of BIT(7)
Overall it's minor and we can support this using the existing enum sm5502_types plus a few switch/if statements.
---
Interestingly enough the register set (and especially the interrupts) also look *very* similar to Richtek RT8973A (extcon-rt8973a) but I didn't investigate this further.
Note that the changes in this patch are mostly based on guesswork based on a SM5504 driver from Nitin Chaudhary [1] used in some Samsung vendor kernels, since I was not able to find a public datasheet for SM5504.
[1]: https://github.com/NitinChaudharyUSC/MSM8x16_8x26/blob/master/drivers/misc/sm5504.c
--- drivers/extcon/Kconfig | 2 +- drivers/extcon/extcon-sm5502.c | 164 +++++++++++++++++++++++++++++---- drivers/extcon/extcon-sm5502.h | 79 ++++++++++++++++ 3 files changed, 228 insertions(+), 17 deletions(-)
drivers/extcon/Kconfig +1 -1
@@ -154,7 +154,7 @@ config EXTCON_RT8973A from abnormal high input voltage (up to 28V). config EXTCON_SM5502 - tristate "Silicon Mitus SM5502 EXTCON support" + tristate "Silicon Mitus SM5502/SM5504 EXTCON support" depends on I2C select IRQ_DOMAIN select REGMAP_I2C
drivers/extcon/extcon-sm5502.c +148 -16
251 lines not on this page · raw message
drivers/extcon/extcon-sm5502.h +79 -0
107 lines not on this page · raw message
Signature · 1 line
2.31.1
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Stephan,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on chanwoo-extcon/extcon-next]
[also build test WARNING on robh/for-next linus/master v5.13-rc2 next-20210521] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Stephan-Gerhold/extcon-sm5502-Add-support-for-SM5504/20210522-215255 base: https://git.kernel.org/pub/scm/linux/kernel/git/chanwoo/extcon.git extcon-next config: x86_64-randconfig-b001-20210522 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project e84a9b9bb3051c35dea993cdad7b3d2575638f85)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/f9928587360c40e166418ea5b10fc0c210b93330
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Stephan-Gerhold/extcon-sm5502-Add-support-for-SM5504/20210522-215255 git checkout f9928587360c40e166418ea5b10fc0c210b93330
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/extcon/extcon-sm5502.c:696:15: warning: cast to smaller integer type 'enum sm5502_types' from 'const void *' [-Wvoid-pointer-to-enum-cast]
info->type = (enum sm5502_types)device_get_match_data(info->dev);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1 warning generated.
vim +696 drivers/extcon/extcon-sm5502.c
914b881f9452fd Chanwoo Choi 2014-05-22 677
9e92a019f01894 Stephan Gerhold 2021-05-20 678 static int sm5022_muic_i2c_probe(struct i2c_client *i2c)
914b881f9452fd Chanwoo Choi 2014-05-22 679 {
914b881f9452fd Chanwoo Choi 2014-05-22 680 struct device_node *np = i2c->dev.of_node;
f9928587360c40 Stephan Gerhold 2021-05-20 681 const struct regmap_irq_chip *irq_chip;
914b881f9452fd Chanwoo Choi 2014-05-22 682 struct sm5502_muic_info *info;
914b881f9452fd Chanwoo Choi 2014-05-22 683 int i, ret, irq_flags;
914b881f9452fd Chanwoo Choi 2014-05-22 684
914b881f9452fd Chanwoo Choi 2014-05-22 685 if (!np)
914b881f9452fd Chanwoo Choi 2014-05-22 686 return -EINVAL;
914b881f9452fd Chanwoo Choi 2014-05-22 687
914b881f9452fd Chanwoo Choi 2014-05-22 688 info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL);
914b881f9452fd Chanwoo Choi 2014-05-22 689 if (!info)
914b881f9452fd Chanwoo Choi 2014-05-22 690 return -ENOMEM;
914b881f9452fd Chanwoo Choi 2014-05-22 691 i2c_set_clientdata(i2c, info);
914b881f9452fd Chanwoo Choi 2014-05-22 692
914b881f9452fd Chanwoo Choi 2014-05-22 693 info->dev = &i2c->dev;
914b881f9452fd Chanwoo Choi 2014-05-22 694 info->i2c = i2c;
914b881f9452fd Chanwoo Choi 2014-05-22 695 info->irq = i2c->irq;
f9928587360c40 Stephan Gerhold 2021-05-20 @696 info->type = (enum sm5502_types)device_get_match_data(info->dev);
f9928587360c40 Stephan Gerhold 2021-05-20 697
f9928587360c40 Stephan Gerhold 2021-05-20 698 switch (info->type) {
f9928587360c40 Stephan Gerhold 2021-05-20 699 case TYPE_SM5502:
f9928587360c40 Stephan Gerhold 2021-05-20 700 irq_chip = &sm5502_muic_irq_chip;
914b881f9452fd Chanwoo Choi 2014-05-22 701 info->muic_irqs = sm5502_muic_irqs;
914b881f9452fd Chanwoo Choi 2014-05-22 702 info->num_muic_irqs = ARRAY_SIZE(sm5502_muic_irqs);
914b881f9452fd Chanwoo Choi 2014-05-22 703 info->reg_data = sm5502_reg_data;
914b881f9452fd Chanwoo Choi 2014-05-22 704 info->num_reg_data = ARRAY_SIZE(sm5502_reg_data);
f9928587360c40 Stephan Gerhold 2021-05-20 705 break;
f9928587360c40 Stephan Gerhold 2021-05-20 706 case TYPE_SM5504:
f9928587360c40 Stephan Gerhold 2021-05-20 707 irq_chip = &sm5504_muic_irq_chip;
f9928587360c40 Stephan Gerhold 2021-05-20 708 info->muic_irqs = sm5504_muic_irqs;
f9928587360c40 Stephan Gerhold 2021-05-20 709 info->num_muic_irqs = ARRAY_SIZE(sm5504_muic_irqs);
f9928587360c40 Stephan Gerhold 2021-05-20 710 info->reg_data = sm5504_reg_data;
f9928587360c40 Stephan Gerhold 2021-05-20 711 info->num_reg_data = ARRAY_SIZE(sm5504_reg_data);
f9928587360c40 Stephan Gerhold 2021-05-20 712 break;
f9928587360c40 Stephan Gerhold 2021-05-20 713 default:
f9928587360c40 Stephan Gerhold 2021-05-20 714 return -EINVAL;
f9928587360c40 Stephan Gerhold 2021-05-20 715 }
914b881f9452fd Chanwoo Choi 2014-05-22 716
914b881f9452fd Chanwoo Choi 2014-05-22 717 mutex_init(&info->mutex);
914b881f9452fd Chanwoo Choi 2014-05-22 718
914b881f9452fd Chanwoo Choi 2014-05-22 719 INIT_WORK(&info->irq_work, sm5502_muic_irq_work);
914b881f9452fd Chanwoo Choi 2014-05-22 720
914b881f9452fd Chanwoo Choi 2014-05-22 721 info->regmap = devm_regmap_init_i2c(i2c, &sm5502_muic_regmap_config);
914b881f9452fd Chanwoo Choi 2014-05-22 722 if (IS_ERR(info->regmap)) {
914b881f9452fd Chanwoo Choi 2014-05-22 723 ret = PTR_ERR(info->regmap);
914b881f9452fd Chanwoo Choi 2014-05-22 724 dev_err(info->dev, "failed to allocate register map: %d\n",
914b881f9452fd Chanwoo Choi 2014-05-22 725 ret);
914b881f9452fd Chanwoo Choi 2014-05-22 726 return ret;
914b881f9452fd Chanwoo Choi 2014-05-22 727 }
914b881f9452fd Chanwoo Choi 2014-05-22 728
914b881f9452fd Chanwoo Choi 2014-05-22 729 /* Support irq domain for SM5502 MUIC device */
914b881f9452fd Chanwoo Choi 2014-05-22 730 irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED;
f9928587360c40 Stephan Gerhold 2021-05-20 731 ret = devm_regmap_add_irq_chip(info->dev, info->regmap, info->irq,
f9928587360c40 Stephan Gerhold 2021-05-20 732 irq_flags, 0, irq_chip, &info->irq_data);
914b881f9452fd Chanwoo Choi 2014-05-22 733 if (ret != 0) {
914b881f9452fd Chanwoo Choi 2014-05-22 734 dev_err(info->dev, "failed to request IRQ %d: %d\n",
914b881f9452fd Chanwoo Choi 2014-05-22 735 info->irq, ret);
914b881f9452fd Chanwoo Choi 2014-05-22 736 return ret;
914b881f9452fd Chanwoo Choi 2014-05-22 737 }
914b881f9452fd Chanwoo Choi 2014-05-22 738
914b881f9452fd Chanwoo Choi 2014-05-22 739 for (i = 0; i < info->num_muic_irqs; i++) {
914b881f9452fd Chanwoo Choi 2014-05-22 740 struct muic_irq *muic_irq = &info->muic_irqs[i];
363b389106e676 Andrzej Hajda 2015-09-24 741 int virq = 0;
914b881f9452fd Chanwoo Choi 2014-05-22 742
914b881f9452fd Chanwoo Choi 2014-05-22 743 virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq);
914b881f9452fd Chanwoo Choi 2014-05-22 744 if (virq <= 0)
914b881f9452fd Chanwoo Choi 2014-05-22 745 return -EINVAL;
914b881f9452fd Chanwoo Choi 2014-05-22 746 muic_irq->virq = virq;
914b881f9452fd Chanwoo Choi 2014-05-22 747
914b881f9452fd Chanwoo Choi 2014-05-22 748 ret = devm_request_threaded_irq(info->dev, virq, NULL,
914b881f9452fd Chanwoo Choi 2014-05-22 749 sm5502_muic_irq_handler,
005ad18727b489 Vasyl Gomonovych 2019-07-19 750 IRQF_NO_SUSPEND | IRQF_ONESHOT,
914b881f9452fd Chanwoo Choi 2014-05-22 751 muic_irq->name, info);
914b881f9452fd Chanwoo Choi 2014-05-22 752 if (ret) {
fbae30d8dd3545 Chanwoo Choi 2014-08-12 753 dev_err(info->dev,
fbae30d8dd3545 Chanwoo Choi 2014-08-12 754 "failed: irq request (IRQ: %d, error :%d)\n",
fbae30d8dd3545 Chanwoo Choi 2014-08-12 755 muic_irq->irq, ret);
914b881f9452fd Chanwoo Choi 2014-05-22 756 return ret;
914b881f9452fd Chanwoo Choi 2014-05-22 757 }
914b881f9452fd Chanwoo Choi 2014-05-22 758 }
914b881f9452fd Chanwoo Choi 2014-05-22 759
914b881f9452fd Chanwoo Choi 2014-05-22 760 /* Allocate extcon device */
914b881f9452fd Chanwoo Choi 2014-05-22 761 info->edev = devm_extcon_dev_allocate(info->dev, sm5502_extcon_cable);
914b881f9452fd Chanwoo Choi 2014-05-22 762 if (IS_ERR(info->edev)) {
914b881f9452fd Chanwoo Choi 2014-05-22 763 dev_err(info->dev, "failed to allocate memory for extcon\n");
914b881f9452fd Chanwoo Choi 2014-05-22 764 return -ENOMEM;
914b881f9452fd Chanwoo Choi 2014-05-22 765 }
914b881f9452fd Chanwoo Choi 2014-05-22 766
914b881f9452fd Chanwoo Choi 2014-05-22 767 /* Register extcon device */
914b881f9452fd Chanwoo Choi 2014-05-22 768 ret = devm_extcon_dev_register(info->dev, info->edev);
914b881f9452fd Chanwoo Choi 2014-05-22 769 if (ret) {
914b881f9452fd Chanwoo Choi 2014-05-22 770 dev_err(info->dev, "failed to register extcon device\n");
914b881f9452fd Chanwoo Choi 2014-05-22 771 return ret;
914b881f9452fd Chanwoo Choi 2014-05-22 772 }
914b881f9452fd Chanwoo Choi 2014-05-22 773
e1954452f500cb Chanwoo Choi 2014-05-28 774 /*
e1954452f500cb Chanwoo Choi 2014-05-28 775 * Detect accessory after completing the initialization of platform
e1954452f500cb Chanwoo Choi 2014-05-28 776 *
e1954452f500cb Chanwoo Choi 2014-05-28 777 * - Use delayed workqueue to detect cable state and then
e1954452f500cb Chanwoo Choi 2014-05-28 778 * notify cable state to notifiee/platform through uevent.
e1954452f500cb Chanwoo Choi 2014-05-28 779 * After completing the booting of platform, the extcon provider
e1954452f500cb Chanwoo Choi 2014-05-28 780 * driver should notify cable state to upper layer.
e1954452f500cb Chanwoo Choi 2014-05-28 781 */
e1954452f500cb Chanwoo Choi 2014-05-28 782 INIT_DELAYED_WORK(&info->wq_detcable, sm5502_muic_detect_cable_wq);
e1954452f500cb Chanwoo Choi 2014-05-28 783 queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
e1954452f500cb Chanwoo Choi 2014-05-28 784 msecs_to_jiffies(DELAY_MS_DEFAULT));
e1954452f500cb Chanwoo Choi 2014-05-28 785
914b881f9452fd Chanwoo Choi 2014-05-22 786 /* Initialize SM5502 device and print vendor id and version id */
914b881f9452fd Chanwoo Choi 2014-05-22 787 sm5502_init_dev_type(info);
914b881f9452fd Chanwoo Choi 2014-05-22 788
914b881f9452fd Chanwoo Choi 2014-05-22 789 return 0;
914b881f9452fd Chanwoo Choi 2014-05-22 790 }
914b881f9452fd Chanwoo Choi 2014-05-22 791 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org