aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2014-02-03 05:27:26 -0500
committerWolfram Sang <wsa@the-dreams.de>2014-03-05 11:10:26 -0500
commitc33a004c9568cbd4b944a1ab293289822e6d562d (patch)
treea771ac9d27a0002068ae1f3fb10fdab2d589b400
parente89364556824cc7a947f99173af842217074c099 (diff)
i2c: nomadik: factor platform data into state container
Move the former platform data struct nmk_i2c_controller into the per-device state container struct i2c_nmk_client, and remove all the platform data probe path hacks. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> [wsa: use 100kHz as default] Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c115
1 files changed, 42 insertions, 73 deletions
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 4443613514ee..e2a890d84fb7 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -111,22 +111,6 @@ enum i2c_freq_mode {
111}; 111};
112 112
113/** 113/**
114 * struct nmk_i2c_controller - client specific controller configuration
115 * @clk_freq: clock frequency for the operation mode
116 * @tft: Tx FIFO Threshold in bytes
117 * @rft: Rx FIFO Threshold in bytes
118 * @timeout Slave response timeout(ms)
119 * @sm: speed mode
120 */
121struct nmk_i2c_controller {
122 u32 clk_freq;
123 unsigned char tft;
124 unsigned char rft;
125 int timeout;
126 enum i2c_freq_mode sm;
127};
128
129/**
130 * struct i2c_vendor_data - per-vendor variations 114 * struct i2c_vendor_data - per-vendor variations
131 * @has_mtdws: variant has the MTDWS bit 115 * @has_mtdws: variant has the MTDWS bit
132 * @fifodepth: variant FIFO depth 116 * @fifodepth: variant FIFO depth
@@ -174,8 +158,12 @@ struct i2c_nmk_client {
174 * @irq: interrupt line for the controller. 158 * @irq: interrupt line for the controller.
175 * @virtbase: virtual io memory area. 159 * @virtbase: virtual io memory area.
176 * @clk: hardware i2c block clock. 160 * @clk: hardware i2c block clock.
177 * @cfg: machine provided controller configuration.
178 * @cli: holder of client specific data. 161 * @cli: holder of client specific data.
162 * @clk_freq: clock frequency for the operation mode
163 * @tft: Tx FIFO Threshold in bytes
164 * @rft: Rx FIFO Threshold in bytes
165 * @timeout Slave response timeout (ms)
166 * @sm: speed mode
179 * @stop: stop condition. 167 * @stop: stop condition.
180 * @xfer_complete: acknowledge completion for a I2C message. 168 * @xfer_complete: acknowledge completion for a I2C message.
181 * @result: controller propogated result. 169 * @result: controller propogated result.
@@ -188,8 +176,12 @@ struct nmk_i2c_dev {
188 int irq; 176 int irq;
189 void __iomem *virtbase; 177 void __iomem *virtbase;
190 struct clk *clk; 178 struct clk *clk;
191 struct nmk_i2c_controller cfg;
192 struct i2c_nmk_client cli; 179 struct i2c_nmk_client cli;
180 u32 clk_freq;
181 unsigned char tft;
182 unsigned char rft;
183 int timeout;
184 enum i2c_freq_mode sm;
193 int stop; 185 int stop;
194 struct completion xfer_complete; 186 struct completion xfer_complete;
195 int result; 187 int result;
@@ -386,7 +378,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
386 * slsu = cycles / (1000000000 / f) + 1 378 * slsu = cycles / (1000000000 / f) + 1
387 */ 379 */
388 ns = DIV_ROUND_UP_ULL(1000000000ULL, i2c_clk); 380 ns = DIV_ROUND_UP_ULL(1000000000ULL, i2c_clk);
389 switch (dev->cfg.sm) { 381 switch (dev->sm) {
390 case I2C_FREQ_MODE_FAST: 382 case I2C_FREQ_MODE_FAST:
391 case I2C_FREQ_MODE_FAST_PLUS: 383 case I2C_FREQ_MODE_FAST_PLUS:
392 slsu = DIV_ROUND_UP(100, ns); /* Fast */ 384 slsu = DIV_ROUND_UP(100, ns); /* Fast */
@@ -409,7 +401,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
409 * 2 whereas it is 3 for fast and fastplus mode of 401 * 2 whereas it is 3 for fast and fastplus mode of
410 * operation. TODO - high speed support. 402 * operation. TODO - high speed support.
411 */ 403 */
412 div = (dev->cfg.clk_freq > 100000) ? 3 : 2; 404 div = (dev->clk_freq > 100000) ? 3 : 2;
413 405
414 /* 406 /*
415 * generate the mask for baud rate counters. The controller 407 * generate the mask for baud rate counters. The controller
@@ -419,7 +411,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
419 * so set brcr1 to 0. 411 * so set brcr1 to 0.
420 */ 412 */
421 brcr1 = 0 << 16; 413 brcr1 = 0 << 16;
422 brcr2 = (i2c_clk/(dev->cfg.clk_freq * div)) & 0xffff; 414 brcr2 = (i2c_clk/(dev->clk_freq * div)) & 0xffff;
423 415
424 /* set the baud rate counter register */ 416 /* set the baud rate counter register */
425 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); 417 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR);
@@ -430,7 +422,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
430 * TODO - support for fast mode plus (up to 1Mb/s) 422 * TODO - support for fast mode plus (up to 1Mb/s)
431 * and high speed (up to 3.4 Mb/s) 423 * and high speed (up to 3.4 Mb/s)
432 */ 424 */
433 if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { 425 if (dev->sm > I2C_FREQ_MODE_FAST) {
434 dev_err(&dev->adev->dev, 426 dev_err(&dev->adev->dev,
435 "do not support this mode defaulting to std. mode\n"); 427 "do not support this mode defaulting to std. mode\n");
436 brcr2 = i2c_clk/(100000 * 2) & 0xffff; 428 brcr2 = i2c_clk/(100000 * 2) & 0xffff;
@@ -438,11 +430,11 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
438 writel(I2C_FREQ_MODE_STANDARD << 4, 430 writel(I2C_FREQ_MODE_STANDARD << 4,
439 dev->virtbase + I2C_CR); 431 dev->virtbase + I2C_CR);
440 } 432 }
441 writel(dev->cfg.sm << 4, dev->virtbase + I2C_CR); 433 writel(dev->sm << 4, dev->virtbase + I2C_CR);
442 434
443 /* set the Tx and Rx FIFO threshold */ 435 /* set the Tx and Rx FIFO threshold */
444 writel(dev->cfg.tft, dev->virtbase + I2C_TFTR); 436 writel(dev->tft, dev->virtbase + I2C_TFTR);
445 writel(dev->cfg.rft, dev->virtbase + I2C_RFTR); 437 writel(dev->rft, dev->virtbase + I2C_RFTR);
446} 438}
447 439
448/** 440/**
@@ -958,63 +950,32 @@ static const struct i2c_algorithm nmk_i2c_algo = {
958 .functionality = nmk_i2c_functionality 950 .functionality = nmk_i2c_functionality
959}; 951};
960 952
961static struct nmk_i2c_controller u8500_i2c = {
962 .tft = 1, /* Tx FIFO threshold */
963 .rft = 8, /* Rx FIFO threshold */
964 .clk_freq = 400000, /* fast mode operation */
965 .timeout = 200, /* Slave response timeout(ms) */
966 .sm = I2C_FREQ_MODE_FAST,
967};
968
969static void nmk_i2c_of_probe(struct device_node *np, 953static void nmk_i2c_of_probe(struct device_node *np,
970 struct nmk_i2c_controller *pdata) 954 struct nmk_i2c_dev *nmk)
971{ 955{
972 of_property_read_u32(np, "clock-frequency", &pdata->clk_freq); 956 /* Default to 100 kHz if no frequency is given in the node */
957 if (of_property_read_u32(np, "clock-frequency", &nmk->clk_freq))
958 nmk->clk_freq = 100000;
973 959
974 /* This driver only supports 'standard' and 'fast' modes of operation. */ 960 /* This driver only supports 'standard' and 'fast' modes of operation. */
975 if (pdata->clk_freq <= 100000) 961 if (nmk->clk_freq <= 100000)
976 pdata->sm = I2C_FREQ_MODE_STANDARD; 962 nmk->sm = I2C_FREQ_MODE_STANDARD;
977 else 963 else
978 pdata->sm = I2C_FREQ_MODE_FAST; 964 nmk->sm = I2C_FREQ_MODE_FAST;
965 nmk->tft = 1; /* Tx FIFO threshold */
966 nmk->rft = 8; /* Rx FIFO threshold */
967 nmk->timeout = 200; /* Slave response timeout(ms) */
979} 968}
980 969
981static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) 970static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
982{ 971{
983 int ret = 0; 972 int ret = 0;
984 struct nmk_i2c_controller *pdata = dev_get_platdata(&adev->dev);
985 struct device_node *np = adev->dev.of_node; 973 struct device_node *np = adev->dev.of_node;
986 struct nmk_i2c_dev *dev; 974 struct nmk_i2c_dev *dev;
987 struct i2c_adapter *adap; 975 struct i2c_adapter *adap;
988 struct i2c_vendor_data *vendor = id->data; 976 struct i2c_vendor_data *vendor = id->data;
989 u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1; 977 u32 max_fifo_threshold = (vendor->fifodepth / 2) - 1;
990 978
991 if (!pdata) {
992 if (np) {
993 pdata = devm_kzalloc(&adev->dev, sizeof(*pdata), GFP_KERNEL);
994 if (!pdata) {
995 ret = -ENOMEM;
996 goto err_no_mem;
997 }
998 /* Provide the default configuration as a base. */
999 memcpy(pdata, &u8500_i2c, sizeof(struct nmk_i2c_controller));
1000 nmk_i2c_of_probe(np, pdata);
1001 } else
1002 /* No i2c configuration found, using the default. */
1003 pdata = &u8500_i2c;
1004 }
1005
1006 if (pdata->tft > max_fifo_threshold) {
1007 dev_warn(&adev->dev, "requested TX FIFO threshold %u, adjusted down to %u\n",
1008 pdata->tft, max_fifo_threshold);
1009 pdata->tft = max_fifo_threshold;
1010 }
1011
1012 if (pdata->rft > max_fifo_threshold) {
1013 dev_warn(&adev->dev, "requested RX FIFO threshold %u, adjusted down to %u\n",
1014 pdata->rft, max_fifo_threshold);
1015 pdata->rft = max_fifo_threshold;
1016 }
1017
1018 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); 979 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL);
1019 if (!dev) { 980 if (!dev) {
1020 dev_err(&adev->dev, "cannot allocate memory\n"); 981 dev_err(&adev->dev, "cannot allocate memory\n");
@@ -1024,6 +985,20 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1024 dev->vendor = vendor; 985 dev->vendor = vendor;
1025 dev->busy = false; 986 dev->busy = false;
1026 dev->adev = adev; 987 dev->adev = adev;
988 nmk_i2c_of_probe(np, dev);
989
990 if (dev->tft > max_fifo_threshold) {
991 dev_warn(&adev->dev, "requested TX FIFO threshold %u, adjusted down to %u\n",
992 dev->tft, max_fifo_threshold);
993 dev->tft = max_fifo_threshold;
994 }
995
996 if (dev->rft > max_fifo_threshold) {
997 dev_warn(&adev->dev, "requested RX FIFO threshold %u, adjusted down to %u\n",
998 dev->rft, max_fifo_threshold);
999 dev->rft = max_fifo_threshold;
1000 }
1001
1027 amba_set_drvdata(adev, dev); 1002 amba_set_drvdata(adev, dev);
1028 1003
1029 /* Select default pin state */ 1004 /* Select default pin state */
@@ -1060,16 +1035,10 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1060 adap->owner = THIS_MODULE; 1035 adap->owner = THIS_MODULE;
1061 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 1036 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
1062 adap->algo = &nmk_i2c_algo; 1037 adap->algo = &nmk_i2c_algo;
1063 adap->timeout = msecs_to_jiffies(pdata->timeout); 1038 adap->timeout = msecs_to_jiffies(dev->timeout);
1064 snprintf(adap->name, sizeof(adap->name), 1039 snprintf(adap->name, sizeof(adap->name),
1065 "Nomadik I2C at %pR", &adev->res); 1040 "Nomadik I2C at %pR", &adev->res);
1066 1041
1067 /* fetch the controller configuration from machine */
1068 dev->cfg.clk_freq = pdata->clk_freq;
1069 dev->cfg.tft = pdata->tft;
1070 dev->cfg.rft = pdata->rft;
1071 dev->cfg.sm = pdata->sm;
1072
1073 i2c_set_adapdata(adap, dev); 1042 i2c_set_adapdata(adap, dev);
1074 1043
1075 dev_info(&adev->dev, 1044 dev_info(&adev->dev,