i2c.c (bf61c8840efe60fd8f91446860b63338fb424158) | i2c.c (17936b43f0fdede23582d83a45622751409c99b9) |
---|---|
1/* 2 * HCI based Driver for Inside Secure microread NFC Chip - i2c layer 3 * 4 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. --- 4 unchanged lines hidden (view full) --- 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the 17 * Free Software Foundation, Inc., 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 | 1/* 2 * HCI based Driver for Inside Secure microread NFC Chip - i2c layer 3 * 4 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. --- 4 unchanged lines hidden (view full) --- 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the 17 * Free Software Foundation, Inc., 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 |
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 |
|
21#include <linux/module.h> 22#include <linux/i2c.h> 23#include <linux/delay.h> 24#include <linux/slab.h> 25#include <linux/interrupt.h> 26#include <linux/gpio.h> 27 28#include <linux/nfc.h> --- 61 unchanged lines hidden (view full) --- 90{ 91 int i; 92 u8 crc = 0; 93 94 for (i = 0; i < skb->len - 1; i++) 95 crc = crc ^ skb->data[i]; 96 97 if (crc != skb->data[skb->len-1]) { | 23#include <linux/module.h> 24#include <linux/i2c.h> 25#include <linux/delay.h> 26#include <linux/slab.h> 27#include <linux/interrupt.h> 28#include <linux/gpio.h> 29 30#include <linux/nfc.h> --- 61 unchanged lines hidden (view full) --- 92{ 93 int i; 94 u8 crc = 0; 95 96 for (i = 0; i < skb->len - 1; i++) 97 crc = crc ^ skb->data[i]; 98 99 if (crc != skb->data[skb->len-1]) { |
98 pr_err(MICROREAD_I2C_DRIVER_NAME 99 ": CRC error 0x%x != 0x%x\n", 100 crc, skb->data[skb->len-1]); 101 102 pr_info(DRIVER_DESC ": %s : BAD CRC\n", __func__); 103 | 100 pr_err("CRC error 0x%x != 0x%x\n", crc, skb->data[skb->len-1]); 101 pr_info("%s: BAD CRC\n", __func__); |
104 return -EPERM; 105 } 106 107 return 0; 108} 109 110static int microread_i2c_enable(void *phy_id) 111{ --- 43 unchanged lines hidden (view full) --- 155static int microread_i2c_read(struct microread_i2c_phy *phy, 156 struct sk_buff **skb) 157{ 158 int r; 159 u8 len; 160 u8 tmp[MICROREAD_I2C_LLC_MAX_SIZE - 1]; 161 struct i2c_client *client = phy->i2c_dev; 162 | 102 return -EPERM; 103 } 104 105 return 0; 106} 107 108static int microread_i2c_enable(void *phy_id) 109{ --- 43 unchanged lines hidden (view full) --- 153static int microread_i2c_read(struct microread_i2c_phy *phy, 154 struct sk_buff **skb) 155{ 156 int r; 157 u8 len; 158 u8 tmp[MICROREAD_I2C_LLC_MAX_SIZE - 1]; 159 struct i2c_client *client = phy->i2c_dev; 160 |
163 pr_debug("%s\n", __func__); 164 | |
165 r = i2c_master_recv(client, &len, 1); 166 if (r != 1) { | 161 r = i2c_master_recv(client, &len, 1); 162 if (r != 1) { |
167 dev_err(&client->dev, "cannot read len byte\n"); | 163 nfc_err(&client->dev, "cannot read len byte\n"); |
168 return -EREMOTEIO; 169 } 170 171 if ((len < MICROREAD_I2C_LLC_MIN_SIZE) || 172 (len > MICROREAD_I2C_LLC_MAX_SIZE)) { | 164 return -EREMOTEIO; 165 } 166 167 if ((len < MICROREAD_I2C_LLC_MIN_SIZE) || 168 (len > MICROREAD_I2C_LLC_MAX_SIZE)) { |
173 dev_err(&client->dev, "invalid len byte\n"); 174 pr_err("invalid len byte\n"); | 169 nfc_err(&client->dev, "invalid len byte\n"); |
175 r = -EBADMSG; 176 goto flush; 177 } 178 179 *skb = alloc_skb(1 + len, GFP_KERNEL); 180 if (*skb == NULL) { 181 r = -ENOMEM; 182 goto flush; --- 40 unchanged lines hidden (view full) --- 223 int r; 224 225 if (!phy || irq != phy->i2c_dev->irq) { 226 WARN_ON_ONCE(1); 227 return IRQ_NONE; 228 } 229 230 client = phy->i2c_dev; | 170 r = -EBADMSG; 171 goto flush; 172 } 173 174 *skb = alloc_skb(1 + len, GFP_KERNEL); 175 if (*skb == NULL) { 176 r = -ENOMEM; 177 goto flush; --- 40 unchanged lines hidden (view full) --- 218 int r; 219 220 if (!phy || irq != phy->i2c_dev->irq) { 221 WARN_ON_ONCE(1); 222 return IRQ_NONE; 223 } 224 225 client = phy->i2c_dev; |
231 dev_dbg(&client->dev, "IRQ\n"); | |
232 233 if (phy->hard_fault != 0) 234 return IRQ_HANDLED; 235 236 r = microread_i2c_read(phy, &skb); 237 if (r == -EREMOTEIO) { 238 phy->hard_fault = r; 239 --- 18 unchanged lines hidden (view full) --- 258static int microread_i2c_probe(struct i2c_client *client, 259 const struct i2c_device_id *id) 260{ 261 struct microread_i2c_phy *phy; 262 struct microread_nfc_platform_data *pdata = 263 dev_get_platdata(&client->dev); 264 int r; 265 | 226 227 if (phy->hard_fault != 0) 228 return IRQ_HANDLED; 229 230 r = microread_i2c_read(phy, &skb); 231 if (r == -EREMOTEIO) { 232 phy->hard_fault = r; 233 --- 18 unchanged lines hidden (view full) --- 252static int microread_i2c_probe(struct i2c_client *client, 253 const struct i2c_device_id *id) 254{ 255 struct microread_i2c_phy *phy; 256 struct microread_nfc_platform_data *pdata = 257 dev_get_platdata(&client->dev); 258 int r; 259 |
266 dev_dbg(&client->dev, "client %p", client); | 260 dev_dbg(&client->dev, "client %p\n", client); |
267 268 if (!pdata) { | 261 262 if (!pdata) { |
269 dev_err(&client->dev, "client %p: missing platform data", | 263 nfc_err(&client->dev, "client %p: missing platform data\n", |
270 client); 271 return -EINVAL; 272 } 273 274 phy = devm_kzalloc(&client->dev, sizeof(struct microread_i2c_phy), 275 GFP_KERNEL); | 264 client); 265 return -EINVAL; 266 } 267 268 phy = devm_kzalloc(&client->dev, sizeof(struct microread_i2c_phy), 269 GFP_KERNEL); |
276 if (!phy) { 277 dev_err(&client->dev, "Can't allocate microread phy"); | 270 if (!phy) |
278 return -ENOMEM; | 271 return -ENOMEM; |
279 } | |
280 281 i2c_set_clientdata(client, phy); 282 phy->i2c_dev = client; 283 284 r = request_threaded_irq(client->irq, NULL, microread_i2c_irq_thread_fn, 285 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 286 MICROREAD_I2C_DRIVER_NAME, phy); 287 if (r) { | 272 273 i2c_set_clientdata(client, phy); 274 phy->i2c_dev = client; 275 276 r = request_threaded_irq(client->irq, NULL, microread_i2c_irq_thread_fn, 277 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 278 MICROREAD_I2C_DRIVER_NAME, phy); 279 if (r) { |
288 dev_err(&client->dev, "Unable to register IRQ handler"); | 280 nfc_err(&client->dev, "Unable to register IRQ handler\n"); |
289 return r; 290 } 291 292 r = microread_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME, 293 MICROREAD_I2C_FRAME_HEADROOM, 294 MICROREAD_I2C_FRAME_TAILROOM, 295 MICROREAD_I2C_LLC_MAX_PAYLOAD, &phy->hdev); 296 if (r < 0) 297 goto err_irq; 298 | 281 return r; 282 } 283 284 r = microread_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME, 285 MICROREAD_I2C_FRAME_HEADROOM, 286 MICROREAD_I2C_FRAME_TAILROOM, 287 MICROREAD_I2C_LLC_MAX_PAYLOAD, &phy->hdev); 288 if (r < 0) 289 goto err_irq; 290 |
299 dev_info(&client->dev, "Probed"); | 291 nfc_info(&client->dev, "Probed"); |
300 301 return 0; 302 303err_irq: 304 free_irq(client->irq, phy); 305 306 return r; 307} 308 309static int microread_i2c_remove(struct i2c_client *client) 310{ 311 struct microread_i2c_phy *phy = i2c_get_clientdata(client); 312 | 292 293 return 0; 294 295err_irq: 296 free_irq(client->irq, phy); 297 298 return r; 299} 300 301static int microread_i2c_remove(struct i2c_client *client) 302{ 303 struct microread_i2c_phy *phy = i2c_get_clientdata(client); 304 |
313 dev_dbg(&client->dev, "%s\n", __func__); 314 | |
315 microread_remove(phy->hdev); 316 317 free_irq(client->irq, phy); 318 319 return 0; 320} 321 322static struct i2c_device_id microread_i2c_id[] = { --- 18 unchanged lines hidden --- | 305 microread_remove(phy->hdev); 306 307 free_irq(client->irq, phy); 308 309 return 0; 310} 311 312static struct i2c_device_id microread_i2c_id[] = { --- 18 unchanged lines hidden --- |