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

clk: cdce925: Extend match support for OF tables

The driver has an OF match table, still, it uses an ID lookup table for
retrieving match data. Currently, the driver is working on the
assumption that an I2C device registered via OF will always match a
legacy I2C device ID. The correct approach is to have an OF device ID
table using i2c_get_match_data() if the devices are registered via OF/ID.

Unify the OF/ID table by using struct clk_cdce925_chip_info
as match data for both these tables and replace the ID lookup table for
the match data by i2c_get_match_data().

Split the array clk_cdce925_chip_info_tbl[] as individual variables, and
make lines shorter by referring to e.g. &clk_cdce913_info instead of
&clk_cdce925_chip_info_tbl[CDCE913].

Drop enum related to chip type as there is no user.

While at it, remove the trailing comma in the terminator entry for the OF
table making code robust against (theoretical) misrebases or other similar
things where the new entry goes _after_ the termination without the
compiler noticing.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230909150516.10353-1-biju.das.jz@bp.renesas.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Biju Das and committed by
Stephen Boyd
faf6b92e 15f5e2e4

+35 -30
+35 -30
drivers/clk/clk-cdce925.c
··· 25 25 * Model this as 2 PLL clocks which are parents to the outputs. 26 26 */ 27 27 28 - enum { 29 - CDCE913, 30 - CDCE925, 31 - CDCE937, 32 - CDCE949, 33 - }; 34 - 35 28 struct clk_cdce925_chip_info { 36 29 int num_plls; 37 30 int num_outputs; 38 - }; 39 - 40 - static const struct clk_cdce925_chip_info clk_cdce925_chip_info_tbl[] = { 41 - [CDCE913] = { .num_plls = 1, .num_outputs = 3 }, 42 - [CDCE925] = { .num_plls = 2, .num_outputs = 5 }, 43 - [CDCE937] = { .num_plls = 3, .num_outputs = 7 }, 44 - [CDCE949] = { .num_plls = 4, .num_outputs = 9 }, 45 31 }; 46 32 47 33 #define MAX_NUMBER_OF_PLLS 4 ··· 607 621 .read = cdce925_regmap_i2c_read, 608 622 }; 609 623 610 - static const struct i2c_device_id cdce925_id[] = { 611 - { "cdce913", CDCE913 }, 612 - { "cdce925", CDCE925 }, 613 - { "cdce937", CDCE937 }, 614 - { "cdce949", CDCE949 }, 615 - { } 616 - }; 617 - MODULE_DEVICE_TABLE(i2c, cdce925_id); 618 - 619 624 static int cdce925_probe(struct i2c_client *client) 620 625 { 621 626 struct clk_cdce925_chip *data; 622 627 struct device_node *node = client->dev.of_node; 623 - const struct i2c_device_id *id = i2c_match_id(cdce925_id, client); 624 628 const char *parent_name; 625 629 const char *pll_clk_name[MAX_NUMBER_OF_PLLS] = {NULL,}; 626 630 struct clk_init_data init; ··· 641 665 return -ENOMEM; 642 666 643 667 data->i2c_client = client; 644 - data->chip_info = &clk_cdce925_chip_info_tbl[id->driver_data]; 668 + data->chip_info = i2c_get_match_data(client); 645 669 config.max_register = CDCE925_OFFSET_PLL + 646 670 data->chip_info->num_plls * 0x10 - 1; 647 671 data->regmap = devm_regmap_init(&client->dev, &regmap_cdce925_bus, ··· 798 822 return err; 799 823 } 800 824 825 + static const struct clk_cdce925_chip_info clk_cdce913_info = { 826 + .num_plls = 1, 827 + .num_outputs = 3, 828 + }; 829 + 830 + static const struct clk_cdce925_chip_info clk_cdce925_info = { 831 + .num_plls = 2, 832 + .num_outputs = 5, 833 + }; 834 + 835 + static const struct clk_cdce925_chip_info clk_cdce937_info = { 836 + .num_plls = 3, 837 + .num_outputs = 7, 838 + }; 839 + 840 + static const struct clk_cdce925_chip_info clk_cdce949_info = { 841 + .num_plls = 4, 842 + .num_outputs = 9, 843 + }; 844 + 845 + static const struct i2c_device_id cdce925_id[] = { 846 + { "cdce913", (kernel_ulong_t)&clk_cdce913_info }, 847 + { "cdce925", (kernel_ulong_t)&clk_cdce925_info }, 848 + { "cdce937", (kernel_ulong_t)&clk_cdce937_info }, 849 + { "cdce949", (kernel_ulong_t)&clk_cdce949_info }, 850 + { } 851 + }; 852 + MODULE_DEVICE_TABLE(i2c, cdce925_id); 853 + 801 854 static const struct of_device_id clk_cdce925_of_match[] = { 802 - { .compatible = "ti,cdce913" }, 803 - { .compatible = "ti,cdce925" }, 804 - { .compatible = "ti,cdce937" }, 805 - { .compatible = "ti,cdce949" }, 806 - { }, 855 + { .compatible = "ti,cdce913", .data = &clk_cdce913_info }, 856 + { .compatible = "ti,cdce925", .data = &clk_cdce925_info }, 857 + { .compatible = "ti,cdce937", .data = &clk_cdce937_info }, 858 + { .compatible = "ti,cdce949", .data = &clk_cdce949_info }, 859 + { } 807 860 }; 808 861 MODULE_DEVICE_TABLE(of, clk_cdce925_of_match); 809 862