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

mfd: wm8994: Add some OF properties

Add properties for some of the more important bits of platform data and
fill out the binding document.

Not all of the current platform data is suitable for the sort of fixed
configuration that is done using DT, some of it should have runtime
mechanisms added instead and some is unlikely to ever be used in practical
systems.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Mark Brown and committed by
Samuel Ortiz
20fb2772 39aa3b5a

+128 -3
+57 -1
Documentation/devicetree/bindings/sound/wm8994.txt
··· 5 5 6 6 Required properties: 7 7 8 - - compatible : "wlf,wm1811", "wlf,wm8994", "wlf,wm8958" 8 + - compatible : One of "wlf,wm1811", "wlf,wm8994" or "wlf,wm8958". 9 9 10 10 - reg : the I2C address of the device for I2C, the chip select 11 11 number for SPI. 12 + 13 + - gpio-controller : Indicates this device is a GPIO controller. 14 + - #gpio-cells : Must be 2. The first cell is the pin number and the 15 + second cell is used to specify optional parameters (currently unused). 16 + 17 + - AVDD2-supply, DBVDD1-supply, DBVDD2-supply, DBVDD3-supply, CPVDD-supply, 18 + SPKVDD1-supply, SPKVDD2-supply : power supplies for the device, as covered 19 + in Documentation/devicetree/bindings/regulator/regulator.txt 20 + 21 + Optional properties: 22 + 23 + - interrupts : The interrupt line the IRQ signal for the device is 24 + connected to. This is optional, if it is not connected then none 25 + of the interrupt related properties should be specified. 26 + - interrupt-controller : These devices contain interrupt controllers 27 + and may provide interrupt services to other devices if they have an 28 + interrupt line connected. 29 + - interrupt-parent : The parent interrupt controller. 30 + - #interrupt-cells: the number of cells to describe an IRQ, this should be 2. 31 + The first cell is the IRQ number. 32 + The second cell is the flags, encoded as the trigger masks from 33 + Documentation/devicetree/bindings/interrupts.txt 34 + 35 + - wlf,gpio-cfg : A list of GPIO configuration register values. If absent, 36 + no configuration of these registers is performed. If any value is 37 + over 0xffff then the register will be left as default. If present 11 38 + values must be supplied. 39 + 40 + - wlf,micbias-cfg : Two MICBIAS register values for WM1811 or 41 + WM8958. If absent the register defaults will be used. 42 + 43 + - wlf,ldo1ena : GPIO specifier for control of LDO1ENA input to device. 44 + - wlf,ldo2ena : GPIO specifier for control of LDO2ENA input to device. 45 + 46 + - wlf,lineout1-se : If present LINEOUT1 is in single ended mode. 47 + - wlf,lineout2-se : If present LINEOUT2 is in single ended mode. 48 + 49 + - wlf,lineout1-feedback : If present LINEOUT1 has common mode feedback 50 + connected. 51 + - wlf,lineout2-feedback : If present LINEOUT2 has common mode feedback 52 + connected. 53 + 54 + - wlf,ldoena-always-driven : If present LDOENA is always driven. 12 55 13 56 Example: 14 57 15 58 codec: wm8994@1a { 16 59 compatible = "wlf,wm8994"; 17 60 reg = <0x1a>; 61 + 62 + gpio-controller; 63 + #gpio-cells = <2>; 64 + 65 + lineout1-se; 66 + 67 + AVDD2-supply = <&regulator>; 68 + CPVDD-supply = <&regulator>; 69 + DBVDD1-supply = <&regulator>; 70 + DBVDD2-supply = <&regulator>; 71 + DBVDD3-supply = <&regulator>; 72 + SPKVDD1-supply = <&regulator>; 73 + SPKVDD2-supply = <&regulator>; 18 74 };
+71 -2
drivers/mfd/wm8994-core.c
··· 19 19 #include <linux/err.h> 20 20 #include <linux/delay.h> 21 21 #include <linux/mfd/core.h> 22 + #include <linux/of.h> 23 + #include <linux/of_device.h> 24 + #include <linux/of_gpio.h> 22 25 #include <linux/pm_runtime.h> 23 26 #include <linux/regmap.h> 24 27 #include <linux/regulator/consumer.h> ··· 399 396 { 0x102, 0x0 }, 400 397 }; 401 398 399 + #ifdef CONFIG_OF 400 + static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) 401 + { 402 + struct device_node *np = wm8994->dev->of_node; 403 + struct wm8994_pdata *pdata = &wm8994->pdata; 404 + int i; 405 + 406 + if (!np) 407 + return 0; 408 + 409 + if (of_property_read_u32_array(np, "wlf,gpio-cfg", pdata->gpio_defaults, 410 + ARRAY_SIZE(pdata->gpio_defaults)) >= 0) { 411 + for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) { 412 + if (wm8994->pdata.gpio_defaults[i] == 0) 413 + pdata->gpio_defaults[i] 414 + = WM8994_CONFIGURE_GPIO; 415 + } 416 + } 417 + 418 + of_property_read_u32_array(np, "wlf,micbias-cfg", pdata->micbias, 419 + ARRAY_SIZE(pdata->micbias)); 420 + 421 + pdata->lineout1_diff = true; 422 + pdata->lineout2_diff = true; 423 + if (of_find_property(np, "wlf,lineout1-se", NULL)) 424 + pdata->lineout1_diff = false; 425 + if (of_find_property(np, "wlf,lineout2-se", NULL)) 426 + pdata->lineout2_diff = false; 427 + 428 + if (of_find_property(np, "wlf,lineout1-feedback", NULL)) 429 + pdata->lineout1fb = true; 430 + if (of_find_property(np, "wlf,lineout2-feedback", NULL)) 431 + pdata->lineout2fb = true; 432 + 433 + if (of_find_property(np, "wlf,ldoena-always-driven", NULL)) 434 + pdata->lineout2fb = true; 435 + 436 + pdata->ldo[0].enable = of_get_named_gpio(np, "wlf,ldo1ena", 0); 437 + if (pdata->ldo[0].enable < 0) 438 + pdata->ldo[0].enable = 0; 439 + 440 + pdata->ldo[1].enable = of_get_named_gpio(np, "wlf,ldo2ena", 0); 441 + if (pdata->ldo[1].enable < 0) 442 + pdata->ldo[1].enable = 0; 443 + 444 + return 0; 445 + } 446 + #else 447 + static int wm8994_set_pdata_from_of(struct wm8994 *wm8994) 448 + { 449 + return 0; 450 + } 451 + #endif 452 + 402 453 /* 403 454 * Instantiate the generic non-control parts of the device. 404 455 */ ··· 470 413 wm8994->pdata = *pdata; 471 414 } 472 415 pdata = &wm8994->pdata; 416 + 417 + ret = wm8994_set_pdata_from_of(wm8994); 418 + if (ret != 0) 419 + return ret; 473 420 474 421 dev_set_drvdata(wm8994->dev, wm8994); 475 422 ··· 744 683 static int wm8994_i2c_probe(struct i2c_client *i2c, 745 684 const struct i2c_device_id *id) 746 685 { 686 + const struct of_device_id *of_id; 747 687 struct wm8994 *wm8994; 748 688 int ret; 749 689 ··· 755 693 i2c_set_clientdata(i2c, wm8994); 756 694 wm8994->dev = &i2c->dev; 757 695 wm8994->irq = i2c->irq; 758 - wm8994->type = id->driver_data; 696 + 697 + if (i2c->dev.of_node) { 698 + of_id = of_match_device(wm8994_of_match, &i2c->dev); 699 + if (of_id) 700 + wm8994->type = (int)of_id->data; 701 + } else { 702 + wm8994->type = id->driver_data; 703 + } 759 704 760 705 wm8994->regmap = devm_regmap_init_i2c(i2c, &wm8994_base_regmap_config); 761 706 if (IS_ERR(wm8994->regmap)) { ··· 802 733 .name = "wm8994", 803 734 .owner = THIS_MODULE, 804 735 .pm = &wm8994_pm_ops, 805 - .of_match_table = wm8994_of_match, 736 + .of_match_table = of_match_ptr(wm8994_of_match), 806 737 }, 807 738 .probe = wm8994_i2c_probe, 808 739 .remove = wm8994_i2c_remove,