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

i2c: pxa: add OF support

Append these properties in below.
mrvl,i2c-polling
mrvl,i2c-fast-mode

Still keep slave, slave_addr and class in platform data.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>

authored by

Haojian Zhuang and committed by
Haojian Zhuang
63fe122b 699c20f3

+75 -22
+75 -22
drivers/i2c/busses/i2c-pxa.c
··· 29 29 #include <linux/errno.h> 30 30 #include <linux/interrupt.h> 31 31 #include <linux/i2c-pxa.h> 32 + #include <linux/of.h> 33 + #include <linux/of_device.h> 32 34 #include <linux/of_i2c.h> 33 35 #include <linux/platform_device.h> 34 36 #include <linux/err.h> ··· 1046 1044 .functionality = i2c_pxa_functionality, 1047 1045 }; 1048 1046 1047 + static struct of_device_id i2c_pxa_dt_ids[] = { 1048 + { .compatible = "mrvl,pxa-i2c", .data = (void *)REGS_PXA2XX }, 1049 + { .compatible = "mrvl,pwri2c", .data = (void *)REGS_PXA3XX }, 1050 + { .compatible = "mrvl,mmp-twsi", .data = (void *)REGS_PXA2XX }, 1051 + {} 1052 + }; 1053 + MODULE_DEVICE_TABLE(of, i2c_pxa_dt_ids); 1054 + 1055 + static int i2c_pxa_probe_dt(struct platform_device *pdev, struct pxa_i2c *i2c, 1056 + enum pxa_i2c_types *i2c_types) 1057 + { 1058 + struct device_node *np = pdev->dev.of_node; 1059 + const struct of_device_id *of_id = 1060 + of_match_device(i2c_pxa_dt_ids, &pdev->dev); 1061 + int ret; 1062 + 1063 + if (!of_id) 1064 + return 1; 1065 + ret = of_alias_get_id(np, "i2c"); 1066 + if (ret < 0) { 1067 + dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); 1068 + return ret; 1069 + } 1070 + pdev->id = ret; 1071 + if (of_get_property(np, "mrvl,i2c-polling", NULL)) 1072 + i2c->use_pio = 1; 1073 + if (of_get_property(np, "mrvl,i2c-fast-mode", NULL)) 1074 + i2c->fast_mode = 1; 1075 + *i2c_types = (u32)(of_id->data); 1076 + return 0; 1077 + } 1078 + 1079 + static int i2c_pxa_probe_pdata(struct platform_device *pdev, 1080 + struct pxa_i2c *i2c, 1081 + enum pxa_i2c_types *i2c_types) 1082 + { 1083 + struct i2c_pxa_platform_data *plat = pdev->dev.platform_data; 1084 + const struct platform_device_id *id = platform_get_device_id(pdev); 1085 + 1086 + *i2c_types = id->driver_data; 1087 + if (plat) { 1088 + i2c->use_pio = plat->use_pio; 1089 + i2c->fast_mode = plat->fast_mode; 1090 + } 1091 + return 0; 1092 + } 1093 + 1049 1094 static int i2c_pxa_probe(struct platform_device *dev) 1050 1095 { 1051 - struct pxa_i2c *i2c; 1052 - struct resource *res; 1053 1096 struct i2c_pxa_platform_data *plat = dev->dev.platform_data; 1054 - const struct platform_device_id *id = platform_get_device_id(dev); 1055 - enum pxa_i2c_types i2c_type = id->driver_data; 1056 - int ret; 1057 - int irq; 1058 - 1059 - res = platform_get_resource(dev, IORESOURCE_MEM, 0); 1060 - irq = platform_get_irq(dev, 0); 1061 - if (res == NULL || irq < 0) 1062 - return -ENODEV; 1063 - 1064 - if (!request_mem_region(res->start, resource_size(res), res->name)) 1065 - return -ENOMEM; 1097 + enum pxa_i2c_types i2c_type; 1098 + struct pxa_i2c *i2c; 1099 + struct resource *res = NULL; 1100 + int ret, irq; 1066 1101 1067 1102 i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL); 1068 1103 if (!i2c) { 1069 1104 ret = -ENOMEM; 1070 1105 goto emalloc; 1106 + } 1107 + 1108 + ret = i2c_pxa_probe_dt(dev, i2c, &i2c_type); 1109 + if (ret > 0) 1110 + ret = i2c_pxa_probe_pdata(dev, i2c, &i2c_type); 1111 + if (ret < 0) 1112 + goto eclk; 1113 + 1114 + res = platform_get_resource(dev, IORESOURCE_MEM, 0); 1115 + irq = platform_get_irq(dev, 0); 1116 + if (res == NULL || irq < 0) { 1117 + ret = -ENODEV; 1118 + goto eclk; 1119 + } 1120 + 1121 + if (!request_mem_region(res->start, resource_size(res), res->name)) { 1122 + ret = -ENOMEM; 1123 + goto eclk; 1071 1124 } 1072 1125 1073 1126 i2c->adap.owner = THIS_MODULE; ··· 1166 1109 1167 1110 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; 1168 1111 1169 - #ifdef CONFIG_I2C_PXA_SLAVE 1170 1112 if (plat) { 1113 + #ifdef CONFIG_I2C_PXA_SLAVE 1171 1114 i2c->slave_addr = plat->slave_addr; 1172 1115 i2c->slave = plat->slave; 1173 - } 1174 1116 #endif 1117 + i2c->adap.class = plat->class; 1118 + } 1175 1119 1176 1120 clk_enable(i2c->clk); 1177 - 1178 - if (plat) { 1179 - i2c->adap.class = plat->class; 1180 - i2c->use_pio = plat->use_pio; 1181 - i2c->fast_mode = plat->fast_mode; 1182 - } 1183 1121 1184 1122 if (i2c->use_pio) { 1185 1123 i2c->adap.algo = &i2c_pxa_pio_algorithm; ··· 1286 1234 .name = "pxa2xx-i2c", 1287 1235 .owner = THIS_MODULE, 1288 1236 .pm = I2C_PXA_DEV_PM_OPS, 1237 + .of_match_table = i2c_pxa_dt_ids, 1289 1238 }, 1290 1239 .id_table = i2c_pxa_id_table, 1291 1240 };