Lines Matching +full:sel +full:- +full:clk
4 * Copyright (C) 2004-2010 Nokia Corporation
40 struct gpio_desc *clk; member
42 struct gpio_desc *sel; member
46 * cbus_send_bit - sends one bit over the bus
52 gpiod_set_value(host->dat, bit ? 1 : 0); in cbus_send_bit()
53 gpiod_set_value(host->clk, 1); in cbus_send_bit()
54 gpiod_set_value(host->clk, 0); in cbus_send_bit()
58 * cbus_send_data - sends @len amount of data over the bus
67 for (i = len; i > 0; i--) in cbus_send_data()
68 cbus_send_bit(host, data & (1 << (i - 1))); in cbus_send_data()
72 * cbus_receive_bit - receives one bit from the bus
79 gpiod_set_value(host->clk, 1); in cbus_receive_bit()
80 ret = gpiod_get_value(host->dat); in cbus_receive_bit()
81 gpiod_set_value(host->clk, 0); in cbus_receive_bit()
86 * cbus_receive_word - receives 16-bit word from the bus
94 for (i = 16; i > 0; i--) { in cbus_receive_word()
101 ret |= 1 << (i - 1); in cbus_receive_word()
107 * cbus_transfer - transfers data over the bus
121 spin_lock_irqsave(&host->lock, flags); in cbus_transfer()
123 /* Reset state and start of transfer, SEL stays down during transfer */ in cbus_transfer()
124 gpiod_set_value(host->sel, 0); in cbus_transfer()
127 gpiod_direction_output(host->dat, 1); in cbus_transfer()
142 ret = gpiod_direction_input(host->dat); in cbus_transfer()
144 dev_dbg(host->dev, "failed setting direction\n"); in cbus_transfer()
147 gpiod_set_value(host->clk, 1); in cbus_transfer()
151 dev_dbg(host->dev, "failed receiving data\n"); in cbus_transfer()
156 /* Indicate end of transfer, SEL goes up until next transfer */ in cbus_transfer()
157 gpiod_set_value(host->sel, 1); in cbus_transfer()
158 gpiod_set_value(host->clk, 1); in cbus_transfer()
159 gpiod_set_value(host->clk, 0); in cbus_transfer()
162 spin_unlock_irqrestore(&host->lock, flags); in cbus_transfer()
179 return -EINVAL; in cbus_i2c_smbus_xfer()
182 command, data->word); in cbus_i2c_smbus_xfer()
187 data->word = ret; in cbus_i2c_smbus_xfer()
215 adapter = devm_kzalloc(&pdev->dev, sizeof(struct i2c_adapter), in cbus_i2c_probe()
218 return -ENOMEM; in cbus_i2c_probe()
220 chost = devm_kzalloc(&pdev->dev, sizeof(*chost), GFP_KERNEL); in cbus_i2c_probe()
222 return -ENOMEM; in cbus_i2c_probe()
224 if (gpiod_count(&pdev->dev, NULL) != 3) in cbus_i2c_probe()
225 return -ENODEV; in cbus_i2c_probe()
226 chost->clk = devm_gpiod_get_index(&pdev->dev, NULL, 0, GPIOD_OUT_LOW); in cbus_i2c_probe()
227 if (IS_ERR(chost->clk)) in cbus_i2c_probe()
228 return PTR_ERR(chost->clk); in cbus_i2c_probe()
229 chost->dat = devm_gpiod_get_index(&pdev->dev, NULL, 1, GPIOD_IN); in cbus_i2c_probe()
230 if (IS_ERR(chost->dat)) in cbus_i2c_probe()
231 return PTR_ERR(chost->dat); in cbus_i2c_probe()
232 chost->sel = devm_gpiod_get_index(&pdev->dev, NULL, 2, GPIOD_OUT_HIGH); in cbus_i2c_probe()
233 if (IS_ERR(chost->sel)) in cbus_i2c_probe()
234 return PTR_ERR(chost->sel); in cbus_i2c_probe()
235 gpiod_set_consumer_name(chost->clk, "CBUS clk"); in cbus_i2c_probe()
236 gpiod_set_consumer_name(chost->dat, "CBUS dat"); in cbus_i2c_probe()
237 gpiod_set_consumer_name(chost->sel, "CBUS sel"); in cbus_i2c_probe()
239 adapter->owner = THIS_MODULE; in cbus_i2c_probe()
240 adapter->class = I2C_CLASS_HWMON; in cbus_i2c_probe()
241 adapter->dev.parent = &pdev->dev; in cbus_i2c_probe()
242 adapter->dev.of_node = pdev->dev.of_node; in cbus_i2c_probe()
243 adapter->nr = pdev->id; in cbus_i2c_probe()
244 adapter->timeout = HZ; in cbus_i2c_probe()
245 adapter->algo = &cbus_i2c_algo; in cbus_i2c_probe()
246 strscpy(adapter->name, "CBUS I2C adapter", sizeof(adapter->name)); in cbus_i2c_probe()
248 spin_lock_init(&chost->lock); in cbus_i2c_probe()
249 chost->dev = &pdev->dev; in cbus_i2c_probe()
259 { .compatible = "i2c-cbus-gpio", },
269 .name = "i2c-cbus-gpio",
275 MODULE_ALIAS("platform:i2c-cbus-gpio");